QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323253 | #7740. Puzzle: Question Mark | zlxFTH | AC ✓ | 261ms | 17292kb | C++14 | 3.3kb | 2024-02-09 00:45:23 | 2024-02-09 00:45:23 |
Judging History
answer
#include <algorithm>
#include <cstdio>
const int N = 2e3 + 5;
const int A1[3][3] = {
{0, 1, 1},
{2, 2, 1},
{2, 1, 2}
};
const int A2[3][3] = {
{1, 1, 2},
{1, 2, 1},
{0, 2, 2}
};
const int A3[3][3] = {
{1, 2, 1},
{2, 1, 1},
{2, 2, 0}
};
const int A4[3][3] = {
{1, 1, 0},
{2, 1, 2},
{1, 2, 2}
};
const int B[4][4] = {
{1, 1, 2, 2},
{1, 2, 3, 2},
{4, 1, 4, 3},
{4, 4, 3, 3}
};
const int C1[2][4] = {
{1, 1, 2, 2},
{1, 2, 1, 2}
};
const int C2[4][2] = {
{1, 1},
{1, 2},
{2, 1},
{2, 2}
};
const int D1[4][3] = {
{1, 1, 0},
{1, 2, 0},
{0, 1, 2},
{0, 2, 2}
};
const int D2[3][4] = {
{0, 0, 1, 1},
{2, 1, 2, 1},
{2, 2, 0, 0}
};
const int D3[3][4] = {
{2, 2, 0, 0},
{2, 1, 2, 1},
{0, 0, 1, 1}
};
const int E[3][2] = {
{1, 1},
{1, 0},
{0, 1}
};
int ans;
int a[N][N];
void dfs(int X, int Y, int n) {
if (n <= 2) return;
auto write = [&](const auto &mod, int r, int c, int x, int y) {
int nxt = 0;
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
if (!mod[i][j]) continue;
a[x + i][y + j] = ans + mod[i][j];
nxt = std::max(nxt, mod[i][j]);
}
}
ans += nxt;
};
if (n % 4 == 0) {
for (int i = X; i < X + n; i += 4)
for (int j = Y; j < Y + n; j += 4)
write(B, 4, 4, i, j);
return;
}
if (n == 3) return write(A1, 3, 3, X, Y);
if (n % 4 == 2) {
for (int i = X; i + 3 < X + n; i += 4)
write(C2, 4, 2, i, Y + n - 2);
for (int i = Y; i + 3 < Y + n; i += 4)
write(C1, 2, 4, X + n - 2, i);
return dfs(X, Y, n - 2);
}
if (n == 5) {
write(A1, 3, 3, X, Y + 2);
write(E, 3, 2, X, Y);
return write(C1, 2, 4, X + 3, Y);
}
if (n % 4 == 3) {
for (int i = X; i + 3 < X + n; i += 4)
write(C2, 4, 2, i, Y + n - 2);
for (int i = Y; i + 3 < Y + n; i += 4)
write(C1, 2, 4, X + n - 2, i);
write(A1, 3, 3, X + n - 3, Y + n - 3);
return dfs(X, Y, n - 2);
}
if (n == 9) {
write(C1, 2, 4, X, Y);
write(C1, 2, 4, X + n - 2, Y + n - 4);
write(C2, 4, 2, X, Y + n - 2);
write(C2, 4, 2, X + n - 4, Y);
write(A2, 3, 3, X, Y + 4);
write(A1, 3, 3, X + n - 5, Y + n - 3);
write(A3, 3, 3, X + 2, Y);
write(A4, 3, 3, X + n - 3, Y + n - 4 - 3);
write(D3, 3, 4, X + 2, Y + 3);
write(D3, 3, 4, X + 4, Y + 2);
return;
}
if (n % 4 == 1) {
int j = 0;
while (j + 3 < n - 5) {
write(C1, 2, 4, X, Y + j);
write(C1, 2, 4, X + n - 2, Y + j);
j += 4;
}
write(D1, 4, 3, X, Y + j);
write(A2, 3, 3, X, Y + j + 2);
write(A1, 3, 3, X + n - 3, Y + j);
write(C2, 4, 2, X + n - 4, Y + n - 2);
write(D2, 3, 4, X + n - 6, Y + n - 4);
for (int i = X + 4; i + 3 < X + n - 4; i += 4) {
write(C2, 4, 2, i, Y + n - 4);
write(C2, 4, 2, i - 1, Y + n - 2);
}
return dfs(X + 2, Y, n - 4);
}
}
void solve() {
int n;
scanf("%d", &n);
ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) a[i][j] = 0;
dfs(1, 1, n);
printf("%d\n", ans);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) printf("%d%c", a[i][j], " \n"[j == n]);
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1564kb
input:
2 3 4
output:
2 0 1 1 2 2 1 2 1 2 4 1 1 2 2 1 2 3 2 4 1 4 3 4 4 3 3
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 232ms
memory: 4000kb
input:
246 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
0 0 0 0 0 0 0 2 0 1 1 2 2 1 2 1 2 4 1 1 2 2 1 2 3 2 4 1 4 3 4 4 3 3 5 3 3 0 1 1 3 0 2 2 1 0 3 2 1 2 4 4 5 5 0 4 5 4 5 0 8 5 5 6 6 1 1 5 6 7 6 1 2 8 5 8 7 2 1 8 8 7 7 2 2 3 3 4 4 0 0 3 4 3 4 0 0 11 9 9 0 7 7 1 1 9 0 8 8 7 1 2 0 9 8 7 8 2 1 10 10 11 11 0 2 2 10 11 10 11 0 5 5 3 3 4 4 6 6 5 3 4 3 4 6 5...
result:
ok Correct. (246 test cases)
Test #3:
score: 0
Accepted
time: 236ms
memory: 4188kb
input:
64 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
output:
15252 247 247 248 248 251 251 252 252 255 255 256 256 259 259 260 260 263 263 264 264 267 267 268 268 271 271 272 272 275 275 276 276 279 279 280 280 283 283 284 284 287 287 288 288 291 291 292 292 295 295 296 296 299 299 300 300 303 303 304 304 307 307 308 308 311 311 312 312 315 315 316 316 319 31...
result:
ok Correct. (64 test cases)
Test #4:
score: 0
Accepted
time: 242ms
memory: 4760kb
input:
45 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
output:
24180 311 311 312 312 315 315 316 316 319 319 320 320 323 323 324 324 327 327 328 328 331 331 332 332 335 335 336 336 339 339 340 340 343 343 344 344 347 347 348 348 351 351 352 352 355 355 356 356 359 359 360 360 363 363 364 364 367 367 368 368 371 371 372 372 375 375 376 376 379 379 380 380 383 38...
result:
ok Correct. (45 test cases)
Test #5:
score: 0
Accepted
time: 238ms
memory: 5928kb
input:
35 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
output:
31684 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101 ...
result:
ok Correct. (35 test cases)
Test #6:
score: 0
Accepted
time: 235ms
memory: 5972kb
input:
30 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
output:
38220 391 391 392 392 395 395 396 396 399 399 400 400 403 403 404 404 407 407 408 408 411 411 412 412 415 415 416 416 419 419 420 420 423 423 424 424 427 427 428 428 431 431 432 432 435 435 436 436 439 439 440 440 443 443 444 444 447 447 448 448 451 451 452 452 455 455 456 456 459 459 460 460 463 46...
result:
ok Correct. (30 test cases)
Test #7:
score: 0
Accepted
time: 253ms
memory: 17204kb
input:
2 2000 1000
output:
1000000 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 10...
result:
ok Correct. (2 test cases)
Test #8:
score: 0
Accepted
time: 235ms
memory: 17208kb
input:
2 1999 999
output:
999000 1999 1999 2000 2000 2003 2003 2004 2004 2007 2007 2008 2008 2011 2011 2012 2012 2015 2015 2016 2016 2019 2019 2020 2020 2023 2023 2024 2024 2027 2027 2028 2028 2031 2031 2032 2032 2035 2035 2036 2036 2039 2039 2040 2040 2043 2043 2044 2044 2047 2047 2048 2048 2051 2051 2052 2052 2055 2055 205...
result:
ok Correct. (2 test cases)
Test #9:
score: 0
Accepted
time: 223ms
memory: 17292kb
input:
2 1998 998
output:
998000 1997 1997 1998 1998 2001 2001 2002 2002 2005 2005 2006 2006 2009 2009 2010 2010 2013 2013 2014 2014 2017 2017 2018 2018 2021 2021 2022 2022 2025 2025 2026 2026 2029 2029 2030 2030 2033 2033 2034 2034 2037 2037 2038 2038 2041 2041 2042 2042 2045 2045 2046 2046 2049 2049 2050 2050 2053 2053 205...
result:
ok Correct. (2 test cases)
Test #10:
score: 0
Accepted
time: 251ms
memory: 17288kb
input:
2 1997 997
output:
997002 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101...
result:
ok Correct. (2 test cases)
Test #11:
score: 0
Accepted
time: 253ms
memory: 17244kb
input:
2 1996 996
output:
996004 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101...
result:
ok Correct. (2 test cases)
Test #12:
score: 0
Accepted
time: 261ms
memory: 17232kb
input:
2 1995 995
output:
995006 1995 1995 1996 1996 1999 1999 2000 2000 2003 2003 2004 2004 2007 2007 2008 2008 2011 2011 2012 2012 2015 2015 2016 2016 2019 2019 2020 2020 2023 2023 2024 2024 2027 2027 2028 2028 2031 2031 2032 2032 2035 2035 2036 2036 2039 2039 2040 2040 2043 2043 2044 2044 2047 2047 2048 2048 2051 2051 205...
result:
ok Correct. (2 test cases)
Test #13:
score: 0
Accepted
time: 254ms
memory: 17272kb
input:
2 1994 994
output:
994008 1993 1993 1994 1994 1997 1997 1998 1998 2001 2001 2002 2002 2005 2005 2006 2006 2009 2009 2010 2010 2013 2013 2014 2014 2017 2017 2018 2018 2021 2021 2022 2022 2025 2025 2026 2026 2029 2029 2030 2030 2033 2033 2034 2034 2037 2037 2038 2038 2041 2041 2042 2042 2045 2045 2046 2046 2049 2049 205...
result:
ok Correct. (2 test cases)
Test #14:
score: 0
Accepted
time: 251ms
memory: 17244kb
input:
2 1993 993
output:
993012 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101...
result:
ok Correct. (2 test cases)
Test #15:
score: 0
Accepted
time: 245ms
memory: 17208kb
input:
2 1992 992
output:
992016 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101...
result:
ok Correct. (2 test cases)
Test #16:
score: 0
Accepted
time: 242ms
memory: 17220kb
input:
2 1991 991
output:
991020 1991 1991 1992 1992 1995 1995 1996 1996 1999 1999 2000 2000 2003 2003 2004 2004 2007 2007 2008 2008 2011 2011 2012 2012 2015 2015 2016 2016 2019 2019 2020 2020 2023 2023 2024 2024 2027 2027 2028 2028 2031 2031 2032 2032 2035 2035 2036 2036 2039 2039 2040 2040 2043 2043 2044 2044 2047 2047 204...
result:
ok Correct. (2 test cases)
Extra Test:
score: 0
Extra Test Passed