Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid Completion Solution #4786

Closed
wants to merge 16 commits into from
Closed

Grid Completion Solution #4786

wants to merge 16 commits into from

Conversation

lext88
Copy link
Contributor

@lext88 lext88 commented Sep 15, 2024

Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.

  • [ X] I have tested my code.
  • [ X] I have added my solution according to the steps here.
  • [X ] I have followed the code conventions mentioned here.
    • I understand that if it is clear that I have not attempted to follow these conventions, my PR will be closed.
    • If changes are requested, I will re-request a review after addressing them.
  • [ X] I have linked this PR to any issues that it closes.

@lext88 lext88 requested a review from dongliuu as a code owner September 15, 2024 02:58
@lext88
Copy link
Contributor Author

lext88 commented Sep 15, 2024

closes #4702

@TheGamingMousse
Copy link
Contributor

@lext88 you need to add the problem into the problem list for the module

https://github.com/cpinitiative/usaco-guide/blob/master/content/5_Plat/PIE.problems.json

then, in similar fashion to how the other problems are added, add the metadata n stuff for the problem. lmk if you need help w/ that

solutions/platinum/cses-2429.mdx Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Show resolved Hide resolved
@SansPapyrus683 SansPapyrus683 changed the title Create cses-2429.mdx Grid Completion Solution Sep 15, 2024
@SansPapyrus683 SansPapyrus683 marked this pull request as draft September 15, 2024 14:23
@SansPapyrus683
Copy link
Contributor

marked as draft since no explanation yet

solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
Comment on lines +40 to +41
// Initialize arrays for column position of 'A' and column position of 'B' in each
// row
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orphan looks weird, could you even out the lines?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unresolved?

solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
solutions/platinum/cses-2429.mdx Outdated Show resolved Hide resolved
@lext88 lext88 marked this pull request as ready for review September 29, 2024 16:33
Copy link
Member

@ryanchou-dev ryanchou-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also send ac ss? thanks :)

Comment on lines +40 to +41
// Initialize arrays for column position of 'A' and column position of 'B' in each
// row
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unresolved?

Comment on lines +10 to +12
This problem is all about finding the number of valid ways to configure a grid with some special conditions. The key is to break down the grid into manageable pieces.

Save the effort of recalculating factorials and their modular inverses for the binomial coefficient by precomputing them using Fermat's Little Theorem. Then, track the character positions and count the rows and columns with A or B. Additionaly, define a helper function that returns the number of valid configurations based on how many rows we decide to fill with A’s and B’s. This function utilizes the inclusion-exclusion principle to adjust the counts. The outer loop iterates over all possible configurations and sums up the valid configurations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good if you talked more about the intuition of arriving at the solution


// Compute the modular inverse of the largest factorial then do it for all
// factorials in reverse order
inv_fact[n] = modInverse(fact[n], MOD);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we passing in MOD?

};

/** @return The number of valid grid configurations */
auto f = [&](int i, int j, int k) -> ll {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you name this function something more readable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like, valid_configs would be good

Copy link

stale bot commented Oct 19, 2024

This pull request has been automatically marked as stale because it has not had recent activity. Please address the requested changes and re-request reviews. Thank you for your contribution!

@stale stale bot added the stale label Oct 19, 2024
Copy link

stale bot commented Nov 5, 2024

Changes requested have not been made. Free free to create a new PR.

@stale stale bot closed this Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants