### tourist's blog

By tourist, history, 5 weeks ago, , We will hold AtCoder Grand Contest 041. This is the last contest of 2019 that counts for AtCoder Race Ranking.

The point values will be 300 — 700 — 900 — 1200 — 1600 (800 + 800) — 2000.

We are looking forward to your participation! Comments (61)
 » its great!!
 » orz tourist
•  » » So it proves that Codeforces is ratist.
 » tourist can we discuss the problems after the contest here ?
 » What is the current race ranking?
•  » » You can see the current GP30 scoreboard here.
•  » » » Thanks! Also, what's 'W' in some columns?
•  » » » » 5 weeks ago, # ^ | ← Rev. 2 →   It means "Writer." GP30 scores consider writers, who are not permitted to participate in the contest.
 » will we get editorial for this?
 » difficute
 » Hope everyone high rating
 » How to solve C? What all I could deduce is that $n = 2k$ is possible, $n=3$ is possible, but I could not fill with $n=5$.
 » 5 weeks ago, # | ← Rev. 3 →   Is there a nice solution to C? Mine just has hard-coded solutions for $n = 4, 5, 6, 7$ with 3 unique dominoes on every row and column, and puts rectangles of those sizes on the diagonal for cases $n \geq 4$. Case $n = 3$ is trivial, and case $n = 2$ is impossible.
•  » » For n = 4 pretty easy to construct this answer SpoilerbbdeccdefghhfgiiAnd for n = 6 Spoilerbb......c.....c......bb......c.....c
•  » » » What are you trying to say?
•  » » » » no need to use bruteforce for n = 4 and n = 6
•  » » » » » he has to bruteforce 6, for row/col has 3 dominoes, then he can combine with other form.
•  » » » » » » There also easy answer for n = 6 and 3 dominos in each row/column: Spoilerbc..ddbc..eeffhi..gghi....jjlm..kklm
•  » » » » » My bad, didn't notice he edited his comment.
•  » » Can you please share your code for the bruteforce you did?
•  » » » My brute-force was just backtracking with some break conditions: brute-force#include #include #include using namespace std; using ll = long long; const int N = 20; const int T = 3; int fil[N][N]; int row_sum[N]; int col_sum[N]; int res[N][N]; bool can; void rec(int x, int y, int k, int n) { if (can) return; if (y == n-1 && x > 0 && col_sum[x-1] != T) return; if (x >= n) { ++y; x = 0; } if (y > 0 && row_sum[y-1] != T) return; if (y < n && x < n) { if (row_sum[y] > T || col_sum[x] > T) return; } if (y >= n) { can = true; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { res[i][j] = fil[i][j]; } } } else { if (!fil[x][y]) { if (x+1 < n && !fil[x+1][y]) { fil[x][y] = k; fil[x+1][y] = k; ++row_sum[y]; ++col_sum[x]; ++col_sum[x+1]; rec(x+1, y, k+1, n); --row_sum[y]; --col_sum[x]; --col_sum[x+1]; fil[x][y] = 0; fil[x+1][y] = 0; } if (y+1 < n && !fil[x][y+1]) { fil[x][y] = k; fil[x][y+1] = k; ++row_sum[y]; ++row_sum[y+1]; ++col_sum[x]; rec(x+1, y, k+1, n); --row_sum[y]; --row_sum[y+1]; --col_sum[x]; fil[x][y] = 0; fil[x][y+1] = 0; } } rec(x+1, y, k, n); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; rec(0, 0, 1, n); for (int x = 0; x < n; ++x) { for (int y = 0; y < n; ++y) { if (res[x][y] == 0) cout << "."; else cout << (char)('a' + res[x][y]); } cout << '\n'; } } 
•  » » My solution involves finding solution for primes and then duplicating that matrix. And finding solution for a prime involves padding a solution for a multiple of 3 with either a line and a column or two lines and two columns. Solving for a multiple of 3 required combining solution for a 3x3 matrix with 1 piece per line or 2 pieces per line.So I would guess your solution is actually nice.
•  » » Model solution isn't nice either :) I found $n = 7$ case with brute force.
•  » » Am I only one "brute-force" by DRAWING?
•  » » » I got 5 and 7 in one attempt each. Not sure if I'm lucky or there are actually a lot of possible solutions. •  » » You probably always need to hardcode patterns for n=5,7 (3 and 4 are trivial). Solutions that use patterns for $n=3k$ can be tricky because you need the diagonal blocks to have the same number of dominoes and the easiest patterns there have 2, while all other $n$ need to have 3.Here is a solution that avoids it: while $n \ge 6$ is even, divide it by 2, which gives you $2^k \times 2^k$ square blocks. All these blocks have sizes either 4 or an odd number greater than 1. If it's 3 or 4, just use the pattern. Otherwise, use many diagonal blocks 4x4 and one 5x5 or 7x7. We don't use any 3x3 block, so the number of dominoes in each block and therefore in each row/column is the same.
 » 5 weeks ago, # | ← Rev. 2 →   Very sad, that the only wrong answer of my solution for C is n=5 :(
 » When will the editorials be out?
 »
 » Thanks for participating! The editorial is out indeed.I was not sure whether the uniforming or the non-uniforming subtask of E will be solved by more people. According to my calculations, 40 people solved the uniforming one, and 28 people solved the non-uniforming one. Well done!
 » Problem C is also Problem 4 from the 2018 European Girls Mathematical Olympiad xdSee https://artofproblemsolving.com/community/c6h1625929p10191585 for discussion
 » Damn, I wasted half an hour to squeeze D into TL and lacked <2 mins to get C accepted :<. I got O(n^2 log n) tho (log n and solution in editorial is in O(n^2), but all my friends got O(n^2 log n) as well if I'm not mistaken.
 » Final GP30 standings: https://img.atcoder.jp/file/GP30.htmlCongratulations tourist, ecnerwal, Um_nik, ksun48, Petr, wxhtxdy, LHiC, and mnbvmar!
•  » » It is stupid from the position of trying to get the best place in finals, but can you allow maroonrk to participate in the finals, if he is not one of the problemsetters? He gave us some of the best problems this year, and today he did solve F very fast, and it seems that he just left the contest in the middle, so he could easily get at least 3rd place, which would be enough for him to overcome both mnbvmar and abacabadabacaba. Also it shouldn't be too expensive since he is already in Japan :)
•  » » » Thanks for the comment, but I didn't leave the contest.I was trying to improve my N^2logN solution to D and ended up with the 39th place instead of the 3rd. I wish I knew N^2logN was enough...(and E1 was really easy with bitset!)Though I couldn't make it to the finals, I would like to help the organizers in some way. So, maybe I can see you in Japan next year.
•  » » » I like your idea, but still it feels a bit unfair to change the rule after the contest ends.How about allowing maroonrk (or a few more) onsite participation unofficially? i.e., he participates in the same contest from the same room, but the official ranks and medals are given to the 8 official finalists. Something like JPN2 team in IOI2019.
 » 5 weeks ago, # | ← Rev. 2 →   Why the output of following sample case is 8 in problem B ?10 4 8 57 2 3 6 1 6 5 4 6 5
•  » » » Thanks !
•  » » » i have done the similar approach. but i m getting WA.will u pls tell me any TC ? for which i m getting wrong?MY SUBMISSION LINK: https://atcoder.jp/contests/agc041/submissions/9189806
•  » » » » if((v[i]+m)>=v[n-p]) madar++;This may not always be true. As you still have to distribute remaining votes, and what of those votes went to $V_{n-p}$
•  » » » » 4 weeks ago, # ^ | ← Rev. 2 →   Hack: 5 5 2 1 2 4 5 6 8 Answer should be 4.
 » Another piece of stats: 40 people solved D, and 10 of them did it in $O(N^2)$.In any case, be sure to check the $O(N^2)$ solution in the editorial, I like it a lot.
•  » » 5 weeks ago, # ^ | ← Rev. 2 →   can you tell this stat for all problems ? It will help in improving a lot .
•  » » » You can check yourself how many people solved a given problem. As for "solved problem with a certain complexity", come on, no one will take the time to manually analyze thousands of solutions just for you.
•  » » » » How to see it (number of people solved)?
•  » » » If you are looking for complexity for each problem then you can kind of guess them from constraints, for example, for problem B, $N$ $<= 1e5$ . That means $O(N^2)$ is not going to cut it rather $O(N log N)$ will. You can safely assume $10^8$ operations can be done in 1 sec and deduce rest from there.
•  » » Did you expect $O(N^2 \log N)$ to pass?
•  » » » Not really. The only $O(N^2 \log N)$ we had during testing had a very large constant, and I couldn't squeeze it into the time limit. Turns out that simpler $O(N^2 \log N)$ approaches also exist.
 » I'm happy to see that tourist set problem D with the same background of the problem I set before (Score Distribution 3).But I'm unhappy that I get AC 40 mins after contest end. :(
 » $O(n^2)$ solution to F:First, dissect the histogram into a tree of size $O(n^2)$ where each node describes a part of the histogram and is of one of the following types: Init: a leaf denoting an empty column. Join(A, B): merge two nodes (A is on the left, B is on the right), assuming that no rook from A can see any cell from B and vice versa. Add(A): append a bottom row to the histogram. Note that there are $O(n)$ Init and Join nodes.We'll do inclusion-exclusion on the columns which contain at least one non-covered cell. What happens if we set a subset $X$ of columns and we want to count the configurations of rooks which leave none of these columns fully covered? This can be solved by an easy DP/DFS on the tree we just constructed. This DP will return for each node: The number of columns which must be left uncovered, The number of rook configurations in the part of the histogram such that no rook is within any forbidden column, and there is a fully covered forbidden column, The number of rook configurations in the part of the histogram such that no rook is within any forbidden column, and there is no fully covered forbidden column. Init and Join are very simple here. When Adding the row, we can either leave the row empty (there's no fully covered forbidden column now) or we can put some rook (if there was a fully covered column, there will still be one). It's very simple to write all the transitions in $O(1)$ time by preprocessing the powers of 2.How to continue from here? We'll compute this DP for all subsets of columns at once. Each node will now return: need[], where need[k] denotes the sum over all k-element forbidden subsets of columns within this part of histogram of (the number of rook configurations such that there is a fully covered forbidden column), noneed[], defined analogously, only that we count the configurations with no fully covered forbidden column. DP will work in the same way as above, only that we also need to track the number of forbidden columns within the part of the histogram.Init is very simple (and $O(1)$). Join can be easily done in the time proportional to the product of the widths of the histograms, and therefore all Joins will take $O(n^2)$ time. Add can be easily done in time proportional to the width of the histogram, and we can also prove that all Adds will take at most $O(n^2)$ time in total (we can bound the time by the area of the histogram).My code is here, but it was kinda written in rush. Enjoy.
 » When you are using the late-submit strategy and shit suddenly got real » In question A, when the parity is different. Why not we can simply take the minimum of n — a and b — 1
•  » » You are assuming parity can't be changed but it can in change in two possible cases.
•  » » » Can you please tell me a test case where this logic will fail, as I am unable to think of any.
•  » » » » When one of them reaches the end, in the next step parity will change.
•  » » » » 4 weeks ago, # ^ | ← Rev. 2 →   It is given that a
•  » » » » » a — 1 will always be minimum than n — a. But the point is b will also have to reach table 1, so it will take at least b — 1 matches to reach to table 1.
•  » » » » » » For example, for the test case: 10 2 7. A will go to table 1 but B will also have to go to table 1. So the answer would be B — 1, i.e. 7 — 1 = 6.
•  » » » » » » » After two rounds, A will be at table 1 and B will be at table 5. Instead of waiting at table 1, A can move towards B. In this case, they will meet after two more rounds at table 3. Thus, the answer is 4.
•  » » » » » » » » Thank you very much, sir. I did not figured out that A also can move towards B. I feel overwhelmed to see your reply.