QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242916#7740. Puzzle: Question Markbrothernumb2002WA 246ms6692kbC++202.9kb2023-11-07 18:30:552023-11-07 18:30:56

Judging History

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

  • [2023-11-07 18:30:56]
  • 评测
  • 测评结果:WA
  • 用时:246ms
  • 内存:6692kb
  • [2023-11-07 18:30:55]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a, i##_ = b; i < i##_; ++i)

using namespace std;
const int N = 2e3 + 5;
const pair<int, int> S[][4] = {
    {{0, 0}, {0, 1}, {1, 1}, {2, 0}},   {{0, 0}, {0, 2}, {1, 1}, {1, 2}},
    {{0, 0}, {1, -1}, {2, -1}, {2, 0}}, {{0, 0}, {0, 1}, {1, 0}, {1, 2}},
    {{0, 0}, {0, 1}, {1, 0}, {2, 1}},   {{0, 0}, {0, 1}, {1, -1}, {1, 1}},
    {{0, 0}, {1, 1}, {2, 0}, {2, 1}},   {{0, 0}, {0, 2}, {1, 0}, {1, 1}}};
const array<int, 4> Sub[] = {
    // Sub[i] = {u, v, x, y}, T[i] = S[u] + Move(S[v], x, y)
    {0, 6, 1, 0}, {3, 5, 0, 2},
    {4, 7, 1, -1}, {4, 5, 1, 1},  {1, 2, 0, 1}, {7, 6, 0, 1},
    {3, 1, 1, 1}, {0, 2, 1, 0},  {5, 7, 0, -2}, {4, 6, 1, 1},
};
int n, m, a[N][N];
void print() {
    printf("%d\n", m);
    rep(i, 0, n) rep(j, 0, n) printf("%d%c", a[i][j], " \n"[j == n - 1]);
}
const int ans9[][9] = {
    { 0,  1,  1,  2, 12, 12,  3, 13,  3},
    {11,  1, 11, 12,  2, 12,  3,  3, 13},
    {11, 11,  1,  2,  2,  4,  4, 13, 13},
    { 5, 15,  5,  6,  6,  4, 14,  4, 14},
    {15,  5,  5, 16,  6,  7,  7, 14, 14},
    {15, 15, 16,  6, 17,  7, 17,  8,  8},
    { 9,  9, 16, 16, 17, 17,  7,  8, 18},
    {19,  9, 19, 10, 20, 10, 20, 18,  8},
    { 9, 19, 19, 10, 10, 20, 20, 18, 18},
};
void fS(int x, int y, int k) {
    ++m;
    rep(i, 0, 4) a[x + S[k][i].first][y + S[k][i].second] = m;
}
void fT(int x, int y, int k) {
    auto [u, v, dx, dy] = Sub[k];
    fS(x, y, u), fS(x + dx, y + dy, v);
}
void Solve() {
    scanf("%d", &n), m = 0;
    rep(i, 0, n) fill(a[i], a[i] + n, 0);
    int k = n % 4 / 2 * 2, t = (n - k - 9) / 2;
    switch (n % 2) {
    case 0:
        rep(i, 0, n / 2) rep(j, 0, (n - k) / 4)
            fT(i * 2, j * 4, 1);
        if (k)
            for (int i = 0, j = n - k; i < n - k; i += 4)
                fT(i, j, 0);
        break;
    case 1:
        if (n == 3) fT(0, 0, 3);
        else if (n == 5 || n == 7) {
            fS(0, 3, 0), fS(1, 0, 0), fS(1, 2, 4), fS(3, 1, 4), fS(3, 3, 5);
            if (n == 7) fT(0, 5, 0), fT(5, 0, 1), fT(4, 5, 2);
        }
        if (n < 9) break;
        m = 20;
        rep(i, 0, 9) rep(j, 0, 9) a[t + i][j] = ans9[i][j];
        for (int i = t - 2, j = t + 9; i >= 0; i -= 2, j += 2) {
            int cnt = (t - i) / 2 + 1, y = cnt * 4;
            rep(c, 0, cnt) fT(i, c * 4, 1), fT(j, c * 4, 1);
            rep(c, 0, cnt) fT(i + 4 * c, y + 3, 0);
            rep(c, 0, cnt - 1) fT(i + 3 + 4 * c, y + 1, 0);
            fT(i, y, 5), fT(j - 2, y + 1, 7), fT(j - 1, y + 3, 2), fT(j - 4, y + 1, 6);
        }
        if (k) {
            n -= k;
            fT(n - 1, n, 2);
            rep(i, 0, (n - 1) / 4) fT(i * 4, n, 0), fT(n, i * 4, 1);
            n += k;
        }
        break;
    }
    print();
}
int main() {
    int t = 1;
    scanf("%d", &t);
    while (t--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3
4

output:

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

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 246ms
memory: 6692kb

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

result:

wrong answer Participant's solution is incorrect. The size of 3-th piece != 4. (test case 5)