QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#544749#7740. Puzzle: Question Markuser10086WA 148ms6388kbC++142.0kb2024-09-02 19:59:232024-09-02 19:59:23

Judging History

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

  • [2024-09-02 19:59:23]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:6388kb
  • [2024-09-02 19:59:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e3 + 10;

int c, n, a[N][N];

void block24(int i, int j)
{
	// 2 x 4
	c++;
	a[i][j] = a[i + 1][j] = a[i + 1][j + 1] = a[i][j + 2] = c;
	c++;
	a[i][j + 1] = a[i + 1][j + 2] = a[i][j + 3] = a[i + 1][j + 3] = c;
}

void block42(int i, int j)
{
	// 4 x 2
	c++;
	a[i][j] = a[i][j + 1] = a[i + 1][j + 1] = a[i + 2][j] = c;
	c++;
	a[i + 1][j] = a[i + 2][j + 1] = a[i + 3][j] = a[i + 3][j + 1] = c;
}

void put(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
	c++; a[x1][y1] = a[x2][y2] = a[x3][y3] = a[x4][y4] = c;
}

void make_pattern(int n)
{
	if (n == 1) return;
	if (n == 3)
	{
		put(1, 3, 2, 2, 3, 2, 3, 3);
		return;
	}
    make_pattern(n - 4);
    for (int i = 1; i <= n - 5; i += 2) block24(i, n - 3);
    for (int j = 1; j <= n - 5; j += 2) block42(n - 3, j);
    int t = n - 5;
    if (n > 5) put(t, t + 1, t + 1, t + 2, t + 2, t + 1, t + 2, t + 2);
    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);
}

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] << ' ';
}

signed main()
{
	cin.tie(0)->sync_with_stdio(0);
	
	int t; cin >> t;
	while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 148ms
memory: 6388kb

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

result:

wrong answer Jury has better answer. Participant 19, jury 20 (test case 9)