QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#545691 | #7740. Puzzle: Question Mark | user10086 | AC ✓ | 188ms | 19424kb | C++14 | 3.2kb | 2024-09-03 16:17:53 | 2024-09-03 16:17:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int c, n, dx, a[N][N];
void put(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
x1 += dx, x2 += dx, x3 += dx, x4 += dx;
c++; a[x1][y1] = a[x2][y2] = a[x3][y3] = a[x4][y4] = c;
}
void block24(int i, int j)
{
// 2 x 4
put(i, j, i + 1, j, i + 1, j + 1, i, j + 2);
put(i, j + 1, i + 1, j + 2, i, j + 3, i + 1, j + 3);
}
void block42(int i, int j)
{
// 4 x 2
put(i, j, i, j + 1, i + 1, j + 1, i + 2, j);
put(i + 1, j, i + 2, j + 1, i + 3, j, i + 3, j + 1);
}
void make_pattern(int n)
{
if (n < 9)
{
assert(n == 5 || n == 7);
int t = n - 5;
put(t + 1, t + 4, t + 1, t + 5, t + 2, t + 3, t + 2, t + 5);
put(t + 1, t + 3, t + 2, t + 4, t + 3, t + 3, t + 3, t + 4);
put(t + 3, t + 1, t + 3, t + 2, t + 4, t + 1, t + 5, t + 2);
put(t + 4, t + 2, t + 4, t + 3, t + 5, t + 1, t + 5, t + 3);
put(t + 3, t + 5, t + 4, t + 4, t + 5, t + 4, t + 5, t + 5);
if (n == 7) block24(1, 4), block42(4, 1), put(t, t + 1, t + 1, t + 2, t + 2, t + 1, t + 2, t + 2), put(1, 3, 2, 2, 3, 2, 3, 3);
return;
}
if (n == 9)
{
block42(1, 1), block24(1, 6), block42(6, 8), block24(8, 1);
put(1, 4, 1, 5, 2, 3, 2, 5), put(1, 3, 2, 4, 3, 3, 3, 4);
put(5, 1, 5, 2, 6, 1, 7, 2), put(6, 2, 6, 3, 7, 1, 7, 3);
put(8, 5, 9, 5, 9, 6, 8, 7), put(7, 6, 7, 7, 8, 6, 9, 7);
put(3, 8, 4, 9, 5, 8, 5, 9), put(3, 7, 3, 9, 4, 7, 4, 8);
put(3, 5, 3, 6, 4, 5, 5, 6), put(4, 6, 5, 7, 6, 6, 6, 7);
put(4, 3, 4, 4, 5, 3, 6, 4), put(5, 4, 6, 5, 7, 4, 7, 5);
return;
}
if (n % 4 == 3)
{
dx += 2; make_pattern(n - 2); dx -= 2;
for (int i = 1; i <= n - 3; i += 4) block24(1, i);
for (int i = n - 3; i >= 4; i -= 4) block42(i, n - 1);
put(1, n - 2, 1, n - 1, 2, n - 2, 2, n), put(1, n, 2, n - 1, 3, n - 1, 3, n);
}
else
{
dx += 2; make_pattern(n - 4); dx -= 2;
for (int i = 1; i <= n - 5; i += 4) block24(1, i), block24(n - 1, i);
put(1, n - 4, 1, n - 3, 2, n - 4, 3, n - 3), put(2, n - 3, 3, n - 2, 4, n - 3, 4, n - 2);
put(1, n - 2, 1, n - 1, 2, n - 2, 2, n), put(1, n, 2, n - 1, 3, n - 1, 3, n);
for (int i = 4; i <= n - 6; i += 4) block42(i, n - 1), block42(i + 1, n - 3);
put(n - 5, n - 1, n - 5, n, n - 4, n - 2, n - 4, n), put(n - 4, n - 3, n - 4, n - 1, n - 3, n - 3, n - 3, n - 2);
block42(n - 3, n - 1);
put(n - 2, n - 3, n - 2, n - 2, n - 1, n - 3, n, n - 2), put(n - 1, n - 4, n - 1, n - 2, n, n - 4, n, n - 3);
}
}
void solve()
{
cin >> n;
if (n <= 3)
{
if (n == 1) cout << "0\n0\n";
else if (n == 2) cout << "0\n0 0\n0 0\n";
else if (n == 3) cout << "2\n2 1 2\n1 2 2\n1 1 0\n";
return;
}
c = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
a[i][j] = 0;
if (n % 2 == 0)
{
for (int i = 1; i <= n; i += 2)
for (int j = 1; j + 4 - 1 <= n; j += 4)
block24(i, j);
if (n % 4 == 2)
for (int i = 1; i + 4 - 1 <= n; i += 4)
block42(i, n - 1);
}
else make_pattern(n);
cout << c << '\n';
for (int i = 1; i <= n; i++, cout << '\n')
for (int j = 1; j <= n; j++)
cout << a[i][j] << '\t';
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t; cin >> t;
while (t--) solve();
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
2 3 4
output:
2 2 1 2 1 2 2 1 1 0 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: 149ms
memory: 6284kb
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 2 1 2 1 2 2 1 1 0 4 1 2 1 2 1 1 2 2 3 4 3 4 3 3 4 4 5 0 0 2 1 1 0 0 1 2 1 3 3 2 2 5 3 4 4 5 0 4 3 4 5 5 8 1 2 1 2 7 7 1 1 2 2 8 7 3 4 3 4 7 8 3 3 4 4 8 8 5 6 5 6 0 0 5 5 6 6 0 0 11 0 0 11 6 7 6 7 0 11 10 6 6 7 7 0 11 11 10 2 1 1 8 8 10 10 1 2 1 9 8 3 3 2 2 5 8 9 3...
result:
ok Correct. (246 test cases)
Test #3:
score: 0
Accepted
time: 165ms
memory: 5980kb
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 15007 15008 15007 15008 15009 15010 15009 15010 15011 15012 15011 15012 15013 15014 15013 15014 15015 15016 15015 15016 15017 15018 15017 15018 15019 15020 15019 15020 15021 15022 15021 15022 15023 15024 15023 15024 15025 15026 15025 15026 15027 15028 15027 15028 15029 15030 15029 15030 15031 ...
result:
ok Correct. (64 test cases)
Test #4:
score: 0
Accepted
time: 158ms
memory: 7932kb
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 23871 23872 23871 23872 23873 23874 23873 23874 23875 23876 23875 23876 23877 23878 23877 23878 23879 23880 23879 23880 23881 23882 23881 23882 23883 23884 23883 23884 23885 23886 23885 23886 23887 23888 23887 23888 23889 23890 23889 23890 23891 23892 23891 23892 23893 23894 23893 23894 23895 ...
result:
ok Correct. (45 test cases)
Test #5:
score: 0
Accepted
time: 123ms
memory: 6644kb
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: 141ms
memory: 8080kb
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 37831 37832 37831 37832 37833 37834 37833 37834 37835 37836 37835 37836 37837 37838 37837 37838 37839 37840 37839 37840 37841 37842 37841 37842 37843 37844 37843 37844 37845 37846 37845 37846 37847 37848 37847 37848 37849 37850 37849 37850 37851 37852 37851 37852 37853 37854 37853 37854 37855 ...
result:
ok Correct. (30 test cases)
Test #7:
score: 0
Accepted
time: 164ms
memory: 19300kb
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: 152ms
memory: 19400kb
input:
2 1999 999
output:
999000 997003 997004 997003 997004 997005 997006 997005 997006 997007 997008 997007 997008 997009 997010 997009 997010 997011 997012 997011 997012 997013 997014 997013 997014 997015 997016 997015 997016 997017 997018 997017 997018 997019 997020 997019 997020 997021 997022 997021 997022 997023 997024...
result:
ok Correct. (2 test cases)
Test #9:
score: 0
Accepted
time: 156ms
memory: 19332kb
input:
2 1998 998
output:
998000 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 #10:
score: 0
Accepted
time: 166ms
memory: 19364kb
input:
2 1997 997
output:
997002 993013 993014 993013 993014 993017 993018 993017 993018 993021 993022 993021 993022 993025 993026 993025 993026 993029 993030 993029 993030 993033 993034 993033 993034 993037 993038 993037 993038 993041 993042 993041 993042 993045 993046 993045 993046 993049 993050 993049 993050 993053 993054...
result:
ok Correct. (2 test cases)
Test #11:
score: 0
Accepted
time: 165ms
memory: 19268kb
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: 161ms
memory: 19424kb
input:
2 1995 995
output:
995006 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 #13:
score: 0
Accepted
time: 188ms
memory: 19336kb
input:
2 1994 994
output:
994008 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 #14:
score: 0
Accepted
time: 174ms
memory: 19296kb
input:
2 1993 993
output:
993012 989031 989032 989031 989032 989035 989036 989035 989036 989039 989040 989039 989040 989043 989044 989043 989044 989047 989048 989047 989048 989051 989052 989051 989052 989055 989056 989055 989056 989059 989060 989059 989060 989063 989064 989063 989064 989067 989068 989067 989068 989071 989072...
result:
ok Correct. (2 test cases)
Test #15:
score: 0
Accepted
time: 180ms
memory: 19328kb
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: 167ms
memory: 19316kb
input:
2 1991 991
output:
991020 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)
Extra Test:
score: 0
Extra Test Passed