QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487071#7740. Puzzle: Question Marktime_interspaceAC ✓222ms19532kbC++146.2kb2024-07-22 15:47:022024-07-22 15:47:03

Judging History

你现在查看的是最新测评结果

  • [2024-07-22 15:47:03]
  • 评测
  • 测评结果:AC
  • 用时:222ms
  • 内存:19532kb
  • [2024-07-22 15:47:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
int T, n, ans[N][N];
int num;
void solve4(int n)
{
	for (int i = 1; i <= n; i += 4)
		for (int j = 1; j <= n; j += 2)
		{
			ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = ++num;
			ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = ++num;
		}
}
void solve2(int n)
{
	for (int i = 1; i <= n - 2; i += 4)
		for (int j = 1; j <= n; j += 2)
		{
			ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = ++num;
			ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = ++num;
		}
	int i = n - 1;
	for (int j = 1; j <= n - 2; j += 4)
	{
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = ++num;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = ++num;
	}
}
void solve1(int n, int x, int y)
{
    if (n == 1) return;
    if (n == 5)
    {
        ans[x + 1][y + 1] = ans[x + 1][y + 2] = ans[x + 2][y + 1] = ans[x + 2][y + 3] = ++num;
        ans[x + 1][y + 3] = ans[x + 1][y + 4] = ans[x + 2][y + 2] = ans[x + 2][y + 4] = ++num;
        ans[x + 3][y + 1] = ans[x + 3][y + 2] = ans[x + 4][y + 1] = ans[x + 4][y + 3] = ++num;
        ans[x + 3][y + 3] = ans[x + 4][y + 2] = ans[x + 5][y + 2] = ans[x + 5][y + 3] = ++num;
        ans[x + 3][y + 4] = ans[x + 4][y + 5] = ans[x + 5][y + 4] = ans[x + 5][y + 5] = ++num;
        return;
    }
    if (n == 9)
    {
        ans[x + 1][y + 1] = ans[x + 1][y + 3] = ans[x + 2][y + 2] = ans[x + 2][y + 3] = ++num;
        ans[x + 1][y + 2] = ans[x + 2][y + 1] = ans[x + 3][y + 1] = ans[x + 3][y + 2] = ++num;
        ans[x + 1][y + 4] = ans[x + 1][y + 6] = ans[x + 2][y + 4] = ans[x + 2][y + 5] = ++num;
        ans[x + 1][y + 5] = ans[x + 1][y + 7] = ans[x + 2][y + 6] = ans[x + 2][y + 7] = ++num;
        ans[x + 1][y + 8] = ans[x + 1][y + 9] = ans[x + 2][y + 8] = ans[x + 3][y + 9] = ++num;
        ans[x + 2][y + 9] = ans[x + 3][y + 8] = ans[x + 4][y + 8] = ans[x + 4][y + 9] = ++num;
        ans[x + 5][y + 8] = ans[x + 5][y + 9] = ans[x + 6][y + 7] = ans[x + 6][y + 9] = ++num;
        ans[x + 6][y + 6] = ans[x + 6][y + 8] = ans[x + 7][y + 6] = ans[x + 7][y + 7] = ++num;
        ans[x + 7][y + 8] = ans[x + 7][y + 9] = ans[x + 8][y + 9] = ans[x + 9][y + 8] = ++num;
        ans[x + 8][y + 7] = ans[x + 8][y + 8] = ans[x + 9][y + 7] = ans[x + 9][y + 9] = ++num;
        ans[x + 8][y + 3] = ans[x + 8][y + 4] = ans[x + 9][y + 3] = ans[x + 9][y + 5] = ++num;
        ans[x + 8][y + 5] = ans[x + 8][y + 6] = ans[x + 9][y + 4] = ans[x + 9][y + 6] = ++num;
        ans[x + 6][y + 1] = ans[x + 6][y + 2] = ans[x + 7][y + 2] = ans[x + 8][y + 1] = ++num;
        ans[x + 7][y + 1] = ans[x + 8][y + 2] = ans[x + 9][y + 1] = ans[x + 9][y + 2] = ++num;
        ans[x + 3][y + 3] = ans[x + 3][y + 4] = ans[x + 4][y + 2] = ans[x + 4][y + 4] = ++num;
        ans[x + 4][y + 1] = ans[x + 4][y + 3] = ans[x + 5][y + 1] = ans[x + 5][y + 2] = ++num;
        ans[x + 3][y + 5] = ans[x + 3][y + 7] = ans[x + 4][y + 5] = ans[x + 4][y + 6] = ++num;
        ans[x + 3][y + 6] = ans[x + 4][y + 7] = ans[x + 5][y + 6] = ans[x + 5][y + 7] = ++num;
        ans[x + 5][y + 3] = ans[x + 5][y + 4] = ans[x + 6][y + 4] = ans[x + 7][y + 3] = ++num;
        ans[x + 6][y + 3] = ans[x + 6][y + 5] = ans[x + 7][y + 4] = ans[x + 7][y + 5] = ++num;
        return;
    }
    for (int i = 0; i <= n - 8; i += 4)
    {
        ans[x + i + 1][y + 1] = ans[x + i + 1][y + 2] = ans[x + i + 2][y + 2] = ans[x + i + 3][y + 1] = ++num;
        ans[x + i + 2][y + 1] = ans[x + i + 3][y + 2] = ans[x + i + 4][y + 1] = ans[x + i + 4][y + 2] = ++num;
        ans[x + i + 1][y + n - 1] = ans[x + i + 1][y + n] = ans[x + i + 2][y + n] = ans[x + i + 3][y + n - 1] = ++num;
        ans[x + i + 2][y + n - 1] = ans[x + i + 3][y + n] = ans[x + i + 4][y + n - 1] = ans[x + i + 4][y + n] = ++num;
    }
    ans[x + n - 4][y + 1] = ans[x + n - 4][y + 2] = ans[x + n - 3][y + 1] = ans[x + n - 3][y + 3] = ++num;
    ans[x + n - 3][y + 2] = ans[x + n - 3][y + 4] = ans[x + n - 2][y + 3] = ans[x + n - 2][y + 4] = ++num;
    ans[x + n - 2][y + 1] = ans[x + n - 2][y + 2] = ans[x + n - 1][y + 2] = ans[x + n][y + 1] = ++num;
    ans[x + n - 1][y + 1] = ans[x + n - 1][y + 3] = ans[x + n][y + 2] = ans[x + n][y + 3] = ++num;
    ans[x + n - 4][y + n - 1] = ans[x + n - 4][y + n] = ans[x + n - 3][y + n] = ans[x + n - 2][y + n - 1] = ++num;
    ans[x + n - 3][y + n - 2] = ans[x + n - 3][y + n - 1] = ans[x + n - 2][y + n - 2] = ans[x + n - 2][y + n] = ++num;
    ans[x + n - 1][y + n - 3] = ans[x + n - 1][y + n - 2] = ans[x + n][y + n - 3] = ans[x + n][y + n - 1] = ++num;
    ans[x + n - 1][y + n - 1] = ans[x + n - 1][y + n] = ans[x + n][y + n - 2] = ans[x + n][y + n] = ++num;
    for (int i = 4; i <= n - 5; i += 2)
    {
        ans[x + n - 3][y + i + 1] = ans[x + n - 3][y + i + 2] = ans[x + n - 2][y + i + 2] = ans[x + n - 1][y + i + 1] = ++num;
        ans[x + n - 2][y + i + 1] = ans[x + n - 1][y + i] = ans[x + n][y + i] = ans[x + n][y + i + 1] = ++num;
    }
    solve1(n - 4, x, y + 2);
}
void solve3(int n)
{
	int i = n - 1;
	for (int j = 1; j <= n - 3; j += 4)
	{
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 1][j + 2] = ++num;
		ans[i + 1][j + 1] = ans[i][j + 2] = ans[i][j + 3] = ans[i + 1][j + 3] = ++num;
	}
	int j = n - 1;
	for (int i = 1; i <= n - 3; i += 4)
	{
		ans[i][j] = ans[i][j + 1] = ans[i + 1][j] = ans[i + 2][j + 1] = ++num;
		ans[i + 1][j + 1] = ans[i + 2][j] = ans[i + 3][j] = ans[i + 3][j + 1] = ++num;
	}
	ans[n - 2][n - 1] = ans[n - 2][n] = ans[n - 1][n - 1] = ans[n][n] = ++num;
	ans[n - 1][n - 2] = ans[n][n - 2] = ans[n][n - 1] = ans[n - 1][n] = ++num;
	solve1(n - 2, 0, 0);
}
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) ans[i][j] = 0;
		num = 0;
		if (n % 4 == 0) solve4(n);
		if (n % 4 == 2) solve2(n);
		if (n % 4 == 3) solve3(n);
		if (n % 4 == 1) solve1(n, 0, 0);
        printf("%d\n", n * n / 4 - (n % 4 == 2 || n == 5 || n == 7));
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
			{
				printf("%d", ans[i][j]);
				if (j < n) putchar(' ');
			}
			puts("");
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3900kb

input:

2
3
4

output:

2
0 1 1
2 1 2
2 2 1
4
1 1 3 3
1 2 3 4
2 1 4 3
2 2 4 4

result:

ok Correct. (2 test cases)

Test #2:

score: 0
Accepted
time: 205ms
memory: 6452kb

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 1 2
2 2 1
4
1 1 3 3
1 2 3 4
2 1 4 3
2 2 4 4
5
1 1 2 2 0
1 2 1 2 0
3 3 4 5 0
3 4 3 0 5
0 4 4 5 5
8
1 1 3 3 5 5
1 2 3 4 5 6
2 1 4 3 6 5
2 2 4 4 6 6
7 7 8 8 0 0
7 8 7 8 0 0
11
7 7 8 8 0 3 3
7 8 7 8 0 3 4
9 9 10 11 0 4 3
9 10 9 0 11 4 4
0 10 10 11 11 5 5
1 1 2 2 6 5 6
1 2 1 2 6 6...

result:

ok Correct. (246 test cases)

Test #3:

score: 0
Accepted
time: 209ms
memory: 6604kb

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 733 733 1211 1211 1681 1681 2143 2143 2597 2597 3043 3043 3481 3481 3911 3911 4333 4333 4747 4747 5153 5153 5551 5551 5941 5941 6323 6323 6697 6697 7063 7063 7421 7421 7771 7771 8113 8113 8447 8447 8773 8773 9091 9091 9401 9401 9703 9703 9997 9997 10283 10283 10561 10561 10831 10831 11...

result:

ok Correct. (64 test cases)

Test #4:

score: 0
Accepted
time: 212ms
memory: 8228kb

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 925 925 1531 1531 2129 2129 2719 2719 3301 3301 3875 3875 4441 4441 4999 4999 5549 5549 6091 6091 6625 6625 7151 7151 7669 7669 8179 8179 8681 8681 9175 9175 9661 9661 10139 10139 10609 10609 11071 11071 11525 11525 11971 11971 12409 12409 12839 12839 13261 13261 13675 13675 14081 1408...

result:

ok Correct. (45 test cases)

Test #5:

score: 0
Accepted
time: 204ms
memory: 6784kb

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 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99 99 101 ...

result:

ok Correct. (35 test cases)

Test #6:

score: 0
Accepted
time: 204ms
memory: 8444kb

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 1165 1165 1931 1931 2689 2689 3439 3439 4181 4181 4915 4915 5641 5641 6359 6359 7069 7069 7771 7771 8465 8465 9151 9151 9829 9829 10499 10499 11161 11161 11815 11815 12461 12461 13099 13099 13729 13729 14351 14351 14965 14965 15571 15571 16169 16169 16759 16759 17341 17341 17915 17915 ...

result:

ok Correct. (30 test cases)

Test #7:

score: 0
Accepted
time: 202ms
memory: 19424kb

input:

2
2000
1000

output:

1000000
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99 99 10...

result:

ok Correct. (2 test cases)

Test #8:

score: 0
Accepted
time: 215ms
memory: 19532kb

input:

2
1999
999

output:

999000
1999 1999 5989 5989 9971 9971 13945 13945 17911 17911 21869 21869 25819 25819 29761 29761 33695 33695 37621 37621 41539 41539 45449 45449 49351 49351 53245 53245 57131 57131 61009 61009 64879 64879 68741 68741 72595 72595 76441 76441 80279 80279 84109 84109 87931 87931 91745 91745 95551 95551...

result:

ok Correct. (2 test cases)

Test #9:

score: 0
Accepted
time: 218ms
memory: 19528kb

input:

2
1998
998

output:

998000
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99 99 101...

result:

ok Correct. (2 test cases)

Test #10:

score: 0
Accepted
time: 188ms
memory: 19524kb

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 97351...

result:

ok Correct. (2 test cases)

Test #11:

score: 0
Accepted
time: 217ms
memory: 19436kb

input:

2
1996
996

output:

996004
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99 99 101...

result:

ok Correct. (2 test cases)

Test #12:

score: 0
Accepted
time: 218ms
memory: 19516kb

input:

2
1995
995

output:

995006
1995 1995 5977 5977 9951 9951 13917 13917 17875 17875 21825 21825 25767 25767 29701 29701 33627 33627 37545 37545 41455 41455 45357 45357 49251 49251 53137 53137 57015 57015 60885 60885 64747 64747 68601 68601 72447 72447 76285 76285 80115 80115 83937 83937 87751 87751 91557 91557 95355 95355...

result:

ok Correct. (2 test cases)

Test #13:

score: 0
Accepted
time: 212ms
memory: 19384kb

input:

2
1994
994

output:

994008
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99 99 101...

result:

ok Correct. (2 test cases)

Test #14:

score: 0
Accepted
time: 219ms
memory: 19460kb

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 97151...

result:

ok Correct. (2 test cases)

Test #15:

score: 0
Accepted
time: 222ms
memory: 19412kb

input:

2
1992
992

output:

992016
1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 61 61 63 63 65 65 67 67 69 69 71 71 73 73 75 75 77 77 79 79 81 81 83 83 85 85 87 87 89 89 91 91 93 93 95 95 97 97 99 99 101...

result:

ok Correct. (2 test cases)

Test #16:

score: 0
Accepted
time: 210ms
memory: 19416kb

input:

2
1991
991

output:

991020
1991 1991 5965 5965 9931 9931 13889 13889 17839 17839 21781 21781 25715 25715 29641 29641 33559 33559 37469 37469 41371 41371 45265 45265 49151 49151 53029 53029 56899 56899 60761 60761 64615 64615 68461 68461 72299 72299 76129 76129 79951 79951 83765 83765 87571 87571 91369 91369 95159 95159...

result:

ok Correct. (2 test cases)

Extra Test:

score: 0
Extra Test Passed