QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267062 | #7740. Puzzle: Question Mark | ValenciaTravis | AC ✓ | 279ms | 19472kb | C++20 | 4.2kb | 2023-11-26 21:55:05 | 2023-11-26 21:55:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define MAXN 2005
int t, n, cnt;
int ans[MAXN][MAXN];
int three[4][3][3] = {
{{0, 1, 1},
{2, 2, 1},
{2, 1, 2}},
{{1, 1, 0},
{1, 2, 2},
{2, 1, 2}},
{{1, 1, 2},
{1, 2, 1},
{0, 2, 2}},
{{1, 2, 1},
{2, 1, 1},
{2, 2, 0}},
};
int four[4][4] = {{1, 1, 2, 2},
{1, 2, 4, 2},
{3, 1, 3, 4},
{3, 3, 4, 4}};
int ver[2][4] = {{1, 1, 2, 2},
{1, 2, 1, 2}};
int hor[4][2] = {{1, 1},
{2, 1},
{1, 2},
{2, 2}};
int tmp[4][4][4] = {
{{1, 1, 0, 0},
{1, 2, 0, 0},
{0, 1, 2, 0},
{0, 2, 2, 0}},
{{0, 1, 1, 0},
{0, 2, 1, 0},
{2, 1, 0, 0},
{2, 2, 0, 0}},
{{1, 1, 0, 0},
{1, 2, 1, 2},
{0, 0, 2, 2},
{0, 0, 0, 0}},
{{0, 0, 2, 2},
{1, 2, 1, 2},
{1, 1, 0, 0},
{0, 0, 0, 0}},
};
void place3(int x, int y, int d){
for(int i=0;i<3;i++) for(int j=0;j<3;j++)
if(three[d][i][j]) ans[x+i][y+j] = cnt + three[d][i][j];
cnt += 2;
}
void place4(int x, int y){
for(int i=0;i<4;i++) for(int j=0;j<4;j++)
ans[x+i][y+j] = cnt + four[i][j];
cnt += 4;
}
void place24_ver(int x, int y){
for(int i=0;i<2;i++) for(int j=0;j<4;j++)
ans[x+i][y+j] = cnt + ver[i][j];
cnt += 2;
}
void place24_hor(int x, int y){
for(int i=0;i<4;i++) for(int j=0;j<2;j++)
ans[x+i][y+j] = cnt + hor[i][j];
cnt += 2;
}
void place24(int x, int y, int d){
for(int i=0;i<4;i++) for(int j=0;j<4;j++)
if(tmp[d][i][j]) ans[x+i][y+j] = cnt + tmp[d][i][j];
cnt += 2;
}
void solve0(int n){
for(int i=1;i<=n;i+=4) for(int j=1;j<=n;j+=4) place4(i, j);
}
void solve2(int n){
solve0(n-2);
int x = n/4*4+1;
for(int i=1;i<=n-2;i+=4) place24_ver(x, i), place24_hor(i, x);
}
void solve1(int l, int r){
if(r-l+1 == 9){
place24_hor(1, l);
place3(5, l, 1);
place24_ver(8, l);
place3(1, l+2, 3);
place24(4, l+2, 0);
place24_ver(1, l+5);
place3(3, l+4, 1);
place24_hor(3, l+7);
place24(6, l+4, 1);
place3(7, l+6, 0);
return;
}
int len = r-l+1;
for(int i=1;i<=len-5;i+=4) place24_hor(i, l), place24_hor(i, r-1);
place24(len-4, l, 2);
place3(len-2, l, 1);
for(int i=l+4;i<=r-5;i+=4) place24_ver(len-3, i), place24_ver(len-1, i-1);
place24(len-3, r-5, 1);
place24_ver(len-1, r-3);
place3(len-4, r-2, 0);
solve1(l+2, r-2);
}
void solve3(int n){
solve1(1, n-2);
int x = n/4*4+2;
for(int i=1;i<=n-3;i+=4) place24_ver(x, i), place24_hor(i, x);
place3(n-2, n-2, 0);
}
void solve5(){
place24_hor(1, 1);
place3(1, 3, 0);
++cnt;
ans[5][3] = ans[5][5] = ans[4][4] = ans[4][5] = cnt;
}
void solve7(){
place3(1, 1, 3);
place24_hor(4, 1);
place24(1, 3, 1);
place24_hor(1, 6);
place3(5, 5, 0);
++cnt;
ans[5][3] = ans[6][4] = ans[7][3] = ans[7][4] = cnt;
}
void work(){
scanf("%d", &n);
cnt = 0;
if(n == 1) return (void)puts("0\n0");
if(n == 2) return (void)puts("0\n0 0\n0 0\n");
if(n == 3) place3(1, 1, 0);
else if(n % 4 == 0) solve0(n);
else if(n % 4 == 2) solve2(n);
else if(n == 5) solve5();
else if(n % 4 == 1) solve1(1, n);
else if(n == 7) solve7();
else if(n % 4 == 3) solve3(n);
printf("%d\n", cnt);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) printf("%2d%c", ans[i][j], " \n"[j==n]);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans[i][j] = 0;
}
int main(){
cin>>t;
while(t--) work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
2 3 4
output:
2 0 1 1 2 2 1 2 1 2 4 1 1 2 2 1 2 4 2 3 1 3 4 3 3 4 4
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 229ms
memory: 6016kb
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 4 2 3 1 3 4 3 3 4 4 5 1 1 0 3 3 2 1 4 4 3 1 2 4 3 4 2 2 0 5 5 0 0 5 0 5 8 1 1 2 2 7 7 1 2 4 2 8 7 3 1 3 4 7 8 3 3 4 4 8 8 5 5 6 6 0 0 5 6 5 6 0 0 11 1 2 1 5 5 ...
result:
ok Correct. (246 test cases)
Test #3:
score: 0
Accepted
time: 230ms
memory: 8156kb
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 1 1 487 487 965 965 1435 1435 1897 1897 2351 2351 2797 2797 3235 3235 3665 3665 4087 4087 4501 4501 4907 4907 5305 5305 5695 5695 6077 6077 6451 6451 6817 6817 7175 7175 7525 7525 7867 7867 8201 8201 8527 8527 8845 8845 9155 9155 9457 9457 9751 9751 10037 10037 10315 10315 10585 10585 10847 ...
result:
ok Correct. (64 test cases)
Test #4:
score: 0
Accepted
time: 239ms
memory: 7672kb
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 1 1 615 615 1221 1221 1819 1819 2409 2409 2991 2991 3565 3565 4131 4131 4689 4689 5239 5239 5781 5781 6315 6315 6841 6841 7359 7359 7869 7869 8371 8371 8865 8865 9351 9351 9829 9829 10299 10299 10761 10761 11215 11215 11661 11661 12099 12099 12529 12529 12951 12951 13365 13365 13771 13771 14...
result:
ok Correct. (45 test cases)
Test #5:
score: 0
Accepted
time: 245ms
memory: 6812kb
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 ...
result:
ok Correct. (35 test cases)
Test #6:
score: 0
Accepted
time: 246ms
memory: 6592kb
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 1 1 775 775 1541 1541 2299 2299 3049 3049 3791 3791 4525 4525 5251 5251 5969 5969 6679 6679 7381 7381 8075 8075 8761 8761 9439 9439 10109 10109 10771 10771 11425 11425 12071 12071 12709 12709 13339 13339 13961 13961 14575 14575 15181 15181 15779 15779 16369 16369 16951 16951 17525 17525 1809...
result:
ok Correct. (30 test cases)
Test #7:
score: 0
Accepted
time: 242ms
memory: 19472kb
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 9...
result:
ok Correct. (2 test cases)
Test #8:
score: 0
Accepted
time: 250ms
memory: 19300kb
input:
2 1999 999
output:
999000 1 1 3991 3991 7973 7973 11947 11947 15913 15913 19871 19871 23821 23821 27763 27763 31697 31697 35623 35623 39541 39541 43451 43451 47353 47353 51247 51247 55133 55133 59011 59011 62881 62881 66743 66743 70597 70597 74443 74443 78281 78281 82111 82111 85933 85933 89747 89747 93553 93553 973...
result:
ok Correct. (2 test cases)
Test #9:
score: 0
Accepted
time: 242ms
memory: 19292kb
input:
2 1998 998
output:
998000 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...
result:
ok Correct. (2 test cases)
Test #10:
score: 0
Accepted
time: 261ms
memory: 19248kb
input:
2 1997 997
output:
997002 1 1 3991 3991 7973 7973 11947 11947 15913 15913 19871 19871 23821 23821 27763 27763 31697 31697 35623 35623 39541 39541 43451 43451 47353 47353 51247 51247 55133 55133 59011 59011 62881 62881 66743 66743 70597 70597 74443 74443 78281 78281 82111 82111 85933 85933 89747 89747 93553 93553 973...
result:
ok Correct. (2 test cases)
Test #11:
score: 0
Accepted
time: 241ms
memory: 19232kb
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...
result:
ok Correct. (2 test cases)
Test #12:
score: 0
Accepted
time: 279ms
memory: 19196kb
input:
2 1995 995
output:
995006 1 1 3983 3983 7957 7957 11923 11923 15881 15881 19831 19831 23773 23773 27707 27707 31633 31633 35551 35551 39461 39461 43363 43363 47257 47257 51143 51143 55021 55021 58891 58891 62753 62753 66607 66607 70453 70453 74291 74291 78121 78121 81943 81943 85757 85757 89563 89563 93361 93361 971...
result:
ok Correct. (2 test cases)
Test #13:
score: 0
Accepted
time: 259ms
memory: 19168kb
input:
2 1994 994
output:
994008 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...
result:
ok Correct. (2 test cases)
Test #14:
score: 0
Accepted
time: 238ms
memory: 19216kb
input:
2 1993 993
output:
993012 1 1 3983 3983 7957 7957 11923 11923 15881 15881 19831 19831 23773 23773 27707 27707 31633 31633 35551 35551 39461 39461 43363 43363 47257 47257 51143 51143 55021 55021 58891 58891 62753 62753 66607 66607 70453 70453 74291 74291 78121 78121 81943 81943 85757 85757 89563 89563 93361 93361 971...
result:
ok Correct. (2 test cases)
Test #15:
score: 0
Accepted
time: 236ms
memory: 19252kb
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...
result:
ok Correct. (2 test cases)
Test #16:
score: 0
Accepted
time: 253ms
memory: 19200kb
input:
2 1991 991
output:
991020 1 1 3975 3975 7941 7941 11899 11899 15849 15849 19791 19791 23725 23725 27651 27651 31569 31569 35479 35479 39381 39381 43275 43275 47161 47161 51039 51039 54909 54909 58771 58771 62625 62625 66471 66471 70309 70309 74139 74139 77961 77961 81775 81775 85581 85581 89379 89379 93169 93169 969...
result:
ok Correct. (2 test cases)
Extra Test:
score: 0
Extra Test Passed