-
Notifications
You must be signed in to change notification settings - Fork 509
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
Grid Completion Solution #4786
Conversation
for more information, see https://pre-commit.ci
closes #4702 |
@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 |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
marked as draft since no explanation yet |
// Initialize arrays for column position of 'A' and column position of 'B' in each | ||
// row |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unresolved?
Co-authored-by: Ryan Chou <[email protected]>
Co-authored-by: Ryan Chou <[email protected]>
for more information, see https://pre-commit.ci
There was a problem hiding this 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 :)
// Initialize arrays for column position of 'A' and column position of 'B' in each | ||
// row |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unresolved?
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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! |
Changes requested have not been made. Free free to create a new PR. |
Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.