QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253827 | #7740. Puzzle: Question Mark | ucup-team902 | AC ✓ | 270ms | 19676kb | C++17 | 5.0kb | 2023-11-17 16:39:11 | 2023-11-17 16:39:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define gc c=getchar()
#define r(x) read(x)
#define ll long long
template<typename T>
inline void read(T &x){
x=0;T k=1;char gc;
while(!isdigit(c)){if(c=='-')k=-1;gc;}
while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}
const int N = 2005;
int pattern[8][3][3] = {
// 0
{{1, 1, 0},
{0, 1, 0},
{1, 0, 0}},
// 1
{{1, 0, 1},
{0, 1, 1},
{0, 0, 0}},
// 2
{{0, 1, 0},
{1, 0, 0},
{1, 1, 0}},
// 3
{{1, 1, 0},
{1, 0, 1},
{0, 0, 0}},
// 4
{{1, 1, 0},
{1, 0, 0},
{0, 1, 0}},
// 5
{{0, 1, 1},
{1, 0, 1},
{0, 0, 0}},
// 6
{{1, 0, 0},
{0, 1, 0},
{1, 1, 0}},
// 7
{{1, 0, 1},
{1, 1, 0},
{0, 0, 0}},
};
int ans5[5][5] = {
{1, 0, 1, 2, 2},
{1, 1, 2, 3, 2},
{0, 0, 3, 4, 4},
{5, 5, 3, 3, 4},
{5, 0, 5, 4, 0}
};
int n;
int tot;
int vis[N][N];
inline void put(int id, int x, int y){
++tot;
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 3; ++j){
if(pattern[id][i][j]){
int px = x + i;
int py = y + j;
assert(0 <= px && px < n && 0 <= py && py < n);
assert(!vis[px][py]);
vis[px][py] = tot;
}
}
}
// for(int i = 0; i < n; ++i){
// for(int j = 0; j < n; ++j){
// printf("%d%c", vis[i][j], "\t\n"[j + 1 == n]);
// }
// }
// puts("---------------");
}
inline void put_type(int id, int x, int y){
switch(id){
case 1:{
put(7, x, y);
put(1, x, y + 1);
break;
}
case 2:{
put(4, x, y);
put(2, x + 1, y);
break;
}
case 3:{
put(0, x, y + 1);
put(3, x + 1, y);
break;
}
case 4:{
put(7, x, y);
put(6, x, y + 1);
break;
}
case 5:{
put(2, x + 1, y);
put(0, x, y + 1);
break;
}
case 6:{
put(3, x, y);
put(1, x + 1, y + 1);
break;
}
}
}
void dfs(int n, int x, int y){
if(n <= 2) return;
if(n % 4 == 0){
for(int i = 0; i < n; i += 2){
for(int j = 0; j < n; j += 4){
put_type(1, x + i, y + j);
}
}
return ;
}
if(n % 4 == 2){
for(int i = 2; i < n; i += 4){
put_type(2, x + i, y);
}
for(int j = 2; j < n; j += 4){
put_type(1, x, y + j);
}
dfs(n - 2, x + 2, y + 2);
return ;
}
if(n % 4 == 3){
if(n == 3){
put_type(3, x, y);
return ;
}
dfs(n - 2, x, y);
int k = n / 4;
for(int i = 0; i < 4 * k; i += 4){
put_type(1, x + 4 * k + 1, y + i);
}
for(int i = 0; i < 4 * k; i += 4){
put_type(2, x + i, y + 4 * k + 1);
}
put_type(3, x + 4 * k, y + 4 * k);
return ;
}
if(n % 4 == 1){
if(n == 5){
put(7, x, y);
put(5, x, y + 2);
put(2, x + 1, y + 2);
put(0, x + 2, y + 3);
put(3, x + 3, y);
return ;
}
if(n == 9){
put(1, x, y);
put(2, x, y);
put_type(1, x, y + 3);
put_type(2, x, y + 7);
put(7, x + 3, y);
put(5, x + 2, y + 1);
put_type(4, x + 2, y + 4);
put(4, x + 4, y + 2);
put(5, x + 5, y + 2);
put(7, x + 5, y + 5);
put(5, x + 4, y + 6);
put_type(2, x + 5, y);
put_type(1, x + 7, y + 2);
put_type(3, x + 6, y + 6);
return ;
}
dfs(n - 4, x + 2, y);
int k = n / 4 - 1;
for(int i = 0; i < 4 * k; i += 4){
put_type(1, x, y + i);
}
put_type(4, x, y + 4 * k);
put_type(2, x, y + 4 * k + 3);
for(int i = 0; i < 4 * k; i += 4){
put_type(1, x + 2 + 4 * k + 1, y + i);
}
put_type(5, x + 4 * k + 1, y + 4 * k);
put_type(3, x + 4 * k + 2, y + 4 * k + 2);
for(int i = 3; i < 4 * k; i += 2){
put_type(6, x + i, y + 4 * k + 1);
}
return ;
}
assert(0);
}
inline void solve(){
r(n);
tot = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
vis[i][j] = 0;
}
}
dfs(n, 0, 0);
printf("%d\n", tot);
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
printf("%d%c", vis[i][j], " \n"[j + 1 == n]);
}
}
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T; r(T);
while(T--){
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
2 3 4
output:
2 0 1 1 2 2 1 2 1 2 4 1 2 1 2 1 1 2 2 3 4 3 4 3 3 4 4
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 238ms
memory: 6620kb
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 2 1 2 1 1 2 2 3 4 3 4 3 3 4 4 5 1 0 1 2 2 1 1 2 3 2 0 0 3 4 4 5 5 3 3 4 5 0 5 4 0 8 0 0 3 4 3 4 0 0 3 3 4 4 1 1 5 6 5 6 1 2 5 5 6 6 2 1 7 8 7 8 2 2 7 7 8 8 11 1 0 1 2 2 8 8 1 1 2 3 2 8 9 0 0 3 4 4 9 8 5 5 3 3 4 9 9 5 0 5 4 0 10 10 6 7 6 7 11 11 10 6 6 7 7 11 10 ...
result:
ok Correct. (246 test cases)
Test #3:
score: 0
Accepted
time: 254ms
memory: 7908kb
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 14521 14522 14521 14522 14523 14524 14523 14524 14525 14526 14525 14526 14527 14528 14527 14528 14529 14530 14529 14530 14531 14532 14531 14532 14533 14534 14533 14534 14535 14536 14535 14536 14537 14538 14537 14538 14539 14540 14539 14540 14541 14542 14541 14542 14543 14544 14543 14544 14545 ...
result:
ok Correct. (64 test cases)
Test #4:
score: 0
Accepted
time: 243ms
memory: 6840kb
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 23257 23258 23257 23258 23259 23260 23259 23260 23261 23262 23261 23262 23263 23264 23263 23264 23265 23266 23265 23266 23267 23268 23267 23268 23269 23270 23269 23270 23271 23272 23271 23272 23273 23274 23273 23274 23275 23276 23275 23276 23277 23278 23277 23278 23279 23280 23279 23280 23281 ...
result:
ok Correct. (45 test cases)
Test #5:
score: 0
Accepted
time: 238ms
memory: 8352kb
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 2 1 2 3 4 3 4 5 6 5 6 7 8 7 8 9 10 9 10 11 12 11 12 13 14 13 14 15 16 15 16 17 18 17 18 19 20 19 20 21 22 21 22 23 24 23 24 25 26 25 26 27 28 27 28 29 30 29 30 31 32 31 32 33 34 33 34 35 36 35 36 37 38 37 38 39 40 39 40 41 42 41 42 43 44 43 44 45 46 45 46 47 48 47 48 49 50 49 50 51 52 51 52 ...
result:
ok Correct. (35 test cases)
Test #6:
score: 0
Accepted
time: 243ms
memory: 6732kb
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 37057 37058 37057 37058 37059 37060 37059 37060 37061 37062 37061 37062 37063 37064 37063 37064 37065 37066 37065 37066 37067 37068 37067 37068 37069 37070 37069 37070 37071 37072 37071 37072 37073 37074 37073 37074 37075 37076 37075 37076 37077 37078 37077 37078 37079 37080 37079 37080 37081 ...
result:
ok Correct. (30 test cases)
Test #7:
score: 0
Accepted
time: 269ms
memory: 19248kb
input:
2 2000 1000
output:
1000000 1 2 1 2 3 4 3 4 5 6 5 6 7 8 7 8 9 10 9 10 11 12 11 12 13 14 13 14 15 16 15 16 17 18 17 18 19 20 19 20 21 22 21 22 23 24 23 24 25 26 25 26 27 28 27 28 29 30 29 30 31 32 31 32 33 34 33 34 35 36 35 36 37 38 37 38 39 40 39 40 41 42 41 42 43 44 43 44 45 46 45 46 47 48 47 48 49 50 49 50 51 52 51 5...
result:
ok Correct. (2 test cases)
Test #8:
score: 0
Accepted
time: 252ms
memory: 19676kb
input:
2 1999 999
output:
999000 993013 993014 993013 993014 993015 993016 993015 993016 993017 993018 993017 993018 993019 993020 993019 993020 993021 993022 993021 993022 993023 993024 993023 993024 993025 993026 993025 993026 993027 993028 993027 993028 993029 993030 993029 993030 993031 993032 993031 993032 993033 993034...
result:
ok Correct. (2 test cases)
Test #9:
score: 0
Accepted
time: 254ms
memory: 19228kb
input:
2 1998 998
output:
998000 0 0 999 1000 999 1000 1001 1002 1001 1002 1003 1004 1003 1004 1005 1006 1005 1006 1007 1008 1007 1008 1009 1010 1009 1010 1011 1012 1011 1012 1013 1014 1013 1014 1015 1016 1015 1016 1017 1018 1017 1018 1019 1020 1019 1020 1021 1022 1021 1022 1023 1024 1023 1024 1025 1026 1025 1026 1027 1028 1...
result:
ok Correct. (2 test cases)
Test #10:
score: 0
Accepted
time: 257ms
memory: 19424kb
input:
2 1997 997
output:
997002 993013 993014 993013 993014 993015 993016 993015 993016 993017 993018 993017 993018 993019 993020 993019 993020 993021 993022 993021 993022 993023 993024 993023 993024 993025 993026 993025 993026 993027 993028 993027 993028 993029 993030 993029 993030 993031 993032 993031 993032 993033 993034...
result:
ok Correct. (2 test cases)
Test #11:
score: 0
Accepted
time: 223ms
memory: 19176kb
input:
2 1996 996
output:
996004 1 2 1 2 3 4 3 4 5 6 5 6 7 8 7 8 9 10 9 10 11 12 11 12 13 14 13 14 15 16 15 16 17 18 17 18 19 20 19 20 21 22 21 22 23 24 23 24 25 26 25 26 27 28 27 28 29 30 29 30 31 32 31 32 33 34 33 34 35 36 35 36 37 38 37 38 39 40 39 40 41 42 41 42 43 44 43 44 45 46 45 46 47 48 47 48 49 50 49 50 51 52 51 52...
result:
ok Correct. (2 test cases)
Test #12:
score: 0
Accepted
time: 270ms
memory: 19372kb
input:
2 1995 995
output:
995006 989031 989032 989031 989032 989033 989034 989033 989034 989035 989036 989035 989036 989037 989038 989037 989038 989039 989040 989039 989040 989041 989042 989041 989042 989043 989044 989043 989044 989045 989046 989045 989046 989047 989048 989047 989048 989049 989050 989049 989050 989051 989052...
result:
ok Correct. (2 test cases)
Test #13:
score: 0
Accepted
time: 252ms
memory: 19236kb
input:
2 1994 994
output:
994008 0 0 997 998 997 998 999 1000 999 1000 1001 1002 1001 1002 1003 1004 1003 1004 1005 1006 1005 1006 1007 1008 1007 1008 1009 1010 1009 1010 1011 1012 1011 1012 1013 1014 1013 1014 1015 1016 1015 1016 1017 1018 1017 1018 1019 1020 1019 1020 1021 1022 1021 1022 1023 1024 1023 1024 1025 1026 1025 ...
result:
ok Correct. (2 test cases)
Test #14:
score: 0
Accepted
time: 229ms
memory: 19624kb
input:
2 1993 993
output:
993012 989031 989032 989031 989032 989033 989034 989033 989034 989035 989036 989035 989036 989037 989038 989037 989038 989039 989040 989039 989040 989041 989042 989041 989042 989043 989044 989043 989044 989045 989046 989045 989046 989047 989048 989047 989048 989049 989050 989049 989050 989051 989052...
result:
ok Correct. (2 test cases)
Test #15:
score: 0
Accepted
time: 247ms
memory: 19184kb
input:
2 1992 992
output:
992016 1 2 1 2 3 4 3 4 5 6 5 6 7 8 7 8 9 10 9 10 11 12 11 12 13 14 13 14 15 16 15 16 17 18 17 18 19 20 19 20 21 22 21 22 23 24 23 24 25 26 25 26 27 28 27 28 29 30 29 30 31 32 31 32 33 34 33 34 35 36 35 36 37 38 37 38 39 40 39 40 41 42 41 42 43 44 43 44 45 46 45 46 47 48 47 48 49 50 49 50 51 52 51 52...
result:
ok Correct. (2 test cases)
Test #16:
score: 0
Accepted
time: 238ms
memory: 19380kb
input:
2 1991 991
output:
991020 985057 985058 985057 985058 985059 985060 985059 985060 985061 985062 985061 985062 985063 985064 985063 985064 985065 985066 985065 985066 985067 985068 985067 985068 985069 985070 985069 985070 985071 985072 985071 985072 985073 985074 985073 985074 985075 985076 985075 985076 985077 985078...
result:
ok Correct. (2 test cases)
Extra Test:
score: 0
Extra Test Passed