using u32=unsigned; u32 constexpr M = 9; u32 n = 0, g[1<<2*M]; template<u32>void solve(u32, u32=0); template<>void solve<2>(u32 voidXY, u32 BaseXY){ u32 e = n++, *p = g+BaseXY, q = g[voidXY]; *p = e, p[1] = e, p += 1<<M, *p = e, p[1] = e, g[voidXY] = q; } template<u32 s> void solve(u32 V, u32 B){ auto constexpr f = solve<s/2>; u32 constexpr m = (1<<M)-1; bool a = (V&~m)<(B&~m)+(s<<M)/2; bool b = (V&+m)<(B&+m)+s/2; f(V, B+(!a)*(s<<M)/2+(!b)*s/2); f(B-a*(1<<M)+b+((s<<M)+s)/2-1, B-a*(s<<(M-1))+b*s/2+(s<<M)/2); f(B+a*(1<<M)+((s<<M)+s)/2-(1<<M)-1, B+a*(s<<M)/2); f(B+a*(1<<M)+((s<<M)+s)/2-(1<<M), B+a*(s<<M)/2+s/2); u32*c = g+((s<<M)+s)/2-(1<<M)+B; c[m+(b&!a)] = c[(a&b)-1] = c[a<<M] = n++; } //this is a very funny, but working program code. Edited by author 03.06.2026 19:49 3 3 2 u need to think wa 10 output for "3 3 2": 1 1 2 2 8 8 6 6 1 5 5 2 8 10 10 6 3 0 5 4 9 9 10 7 3 3 4 4 21 9 7 7 12 12 14 21 21 19 18 18 12 15 14 14 19 19 20 18 11 15 15 13 17 20 20 16 11 11 13 13 17 17 16 16 no overflow, checked all cases for n \in {1, 2, 3} Are you sure? Probably you write for i:=1 to x for j:=1 to y In this case you should switch x and y. I had WA#4 for 3 times, than I replaced scanf("%d %d %d", &n, &x, &y); with scanf("%d %d %d", &n, &y, &x); and got AC! But I'm sure that there is a mistake in tests cuz I think that the first version of my program was right. :-| I also had wa#4 before changing readln(x,y) to readln(y,x)! but now i have AC The same If some inaccurate statement need to be fixed, it's better to write about it to timus_support@acm.timus.ru instead of webboard. I hadn't change x and y, but I still got AC. Maybe something wrong with your program. Read problem statement more careful: The second line consists of two integers x and y — those are the coordinates of the deleted cell (1 <= x, y <= 2n). X is a number of a LINE and Y — a number of a ROW. Yep, and both LINE and ROW usually refer to something horizontal (along with Y coordinate) :) That should be rows/columns for clearer problem statement. OK, I had a mistake in zeroing the matrix at the beginning setup. Now I have AC. Edited by author 23.02.2009 21:24 test: 3 4 5 Tested for input (on my computer): 3 4 5 this program gave me result: 3 3 4 4 8 8 9 9 3 2 2 4 8 7 7 9 5 2 6 6 10 10 7 11 5 5 6 1 1 10 11 11 13 13 14 0 1 18 19 19 13 12 14 14 18 18 17 19 15 12 12 16 20 17 17 21 15 15 16 16 20 20 21 21 I don't see anything wrong here. Maybe I haven't fully and correctly understood the problem? Edited by author 11.04.2008 21:42 your num 0 isn't on the correct place So you mean that I have switched rows and columns? Well, now I have changed the scanf line from (...) &a,&b) to (...) &b,&a) and now I have the following result for this test: 3 3 4 4 8 8 9 9 3 2 2 4 8 7 7 9 5 2 6 6 10 10 7 11 5 5 6 1 0 10 11 11 13 13 14 1 1 18 19 19 13 12 14 14 18 18 17 19 15 12 12 16 20 17 17 21 15 15 16 16 20 20 21 21 But I still have WA #3 :( Also, look at the other posts at the forum about this problem and you'll read that people who have exchanged rows with columns have WA #4. I have WA earlier so there must be something else wrong with my program... :( So, could somebody give the correct solution for test: 3 4 5 ? Maybe I haven't correctly understood this problem? 3 3 4 4 8 8 9 9 3 2 2 4 8 7 7 9 5 2 6 6 10 10 7 11 5 5 6 1 0 10 11 11 13 13 14 1 1 18 19 19 13 12 14 14 18 18 17 19 15 12 12 16 20 17 17 21 15 15 16 16 20 20 21 21 x is row, y is column, I was caught by that (but AFAIK it wasn't WA3) |
|