QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265347#7740. Puzzle: Question Markucup-team1198#WA 197ms6708kbC++204.7kb2023-11-25 17:58:342023-11-25 17:58:34

Judging History

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

  • [2023-11-25 17:58:34]
  • 评测
  • 测评结果:WA
  • 用时:197ms
  • 内存:6708kb
  • [2023-11-25 17:58:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

const int MAXN = 2e3 + 100;
int a[MAXN][MAXN];

int id;

void col24(int i, int j) {
    a[i][j] = a[i + 1][j] = a[i][j + 1] = a[i + 1][j + 2] = id;
    ++id;
    a[i + 1][j + 1] = a[i][j + 2] = a[i][j + 3] = a[i + 1][j + 3] = id;
    ++id;
}

void col42(int i, int j) {
    a[i][j] = a[i][j + 1] = a[i + 1][j] = a[i + 2][j + 1] = id;
    ++id;
    a[i + 1][j + 1] = a[i + 2][j] = a[i + 3][j] = a[i + 3][j + 1] = id;
    ++id;
}

void col33(int i, int j) {
    a[i][j] = a[i + 1][j + 1] = a[i + 2][j] = a[i + 2][j + 1] = id;
    ++id;
    a[i + 1][j] = a[i][j + 1] = a[i][j + 2] = a[i + 1][j + 2] = id;
    ++id;
}

void coli33(int i, int j) {
    a[i + 1][j] = a[i + 2][j] = a[i + 1][j + 1] = a[i + 2][j + 2] = id;
    ++id;
    a[i][j + 1] = a[i][j + 2] = a[i + 1][j + 2] = a[i + 2][j + 1] = id;
    ++id;
}

void collll33(int i, int j) {
    a[i][j] = a[i + 1][j] = a[i][j + 1] = a[i + 2][j + 1] = id;
    ++id;
    a[i + 2][j] = a[i + 1][j + 1] = a[i + 1][j + 2] = a[i + 2][j + 2] = id;
    ++id;
}

void colrrr33(int i, int j) {
    a[i][j] = a[i][j + 1] = a[i + 1][j] = a[i + 1][j + 2] = id;
    ++id;
    a[i][j + 2] = a[i + 1][j + 1] = a[i + 2][j + 1] = a[i + 2][j + 2] = id;
    ++id;
}

void colw1(int i, int j) {
    a[i][j] = a[i][j + 1] = a[i + 1][j] = a[i + 2][j + 1] = id;
    ++id;
    a[i + 1][j + 1] = a[i + 1][j + 2] = a[i + 2][j + 2] = a[i + 3][j + 1] = id;
    ++id;
}

void colw2(int i, int j) {
    a[i][j] = a[i][j + 1] = a[i + 1][j] = a[i + 2][j + 1] = id;
    ++id;
    a[i + 1][j + 1] = a[i + 2][j + 2] = a[i + 3][j + 2] = a[i + 3][j + 1] = id;
    ++id;
}

int sn;

void print() {
    cout << id - 1 << "\n";
    for (int i = 0; i < sn; ++i) {
        for (int j = 0; j < sn; ++j) {
            cout << a[i][j];
            if (j != sn - 1) {
                cout << " ";
            }
        }
        cout << "\n";
    }
}

void solve() {
    int n;
    cin >> n;
    sn = n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            a[i][j] = 0;
        }
    }
    id = 1;
    if (n % 4 == 0) {
        for (int i = 0; i < n; i += 2) {
            for (int j = 0; j < n; j += 4) {
                col24(i, j);
            }
        }
        print();
        return;
    }
    if (n % 4 == 2) {
        for (int i = 0; i < n; i += 2) {
            for (int j = 0; j < n - 2; j += 4) {
                col24(i, j);
            }
        }
        for (int i = 0; i < n - 2; i += 4) {
            col42(i, n - 2);
        }
        print();
        return;
    }
    if (n % 8 == 5 || n % 8 == 7) {
        if (n % 4 == 3) {
            for (int i = 0; i < n - 3; i += 4) {
                col24(n - 2, i);
                col42(i, n - 2);
            }
            coli33(n - 3, n - 3);
            n -= 2;
        }
        if (n < 4) {
            print();
            return;
        }
        int l = 0;
        int r = n;
        while (r - l > 5) {
            col33(l, l);
            for (int i = l + 3; i + 4 <= r; i += 4) {
                col24(l, i);
                col42(i, l);
            }
            for (int i = l; i + 4 <= r; i += 4) {
                col24(r - 2, i);
                if (i != r - 5) {
                    col42(i, r - 2);
                }
            }
            coli33(r - 5, r - 3);
            l += 2;
            r -= 2;
        }
        col33(l, l);
        col24(l + 3, l);
        a[l + 2][l + 2] = a[l + 1][l + 3] = a[l + 1][l + 4] = a[l + 2][l + 4] = id;
        ++id;
        print();
        return;
    }
    int lx = 0, rx = n, ly = 0, ry = n;
    while (rx - lx > 3) {
        int n = rx - lx;
        if ((rx - lx) % 4 == 3) {
            for (int i = 0; i < n - 3; i += 4) {
                col24(lx + n - 2, ly + i);
                col42(lx + i, ly + n - 2);
            }
            coli33(lx + n - 3, ly + n - 3);
            rx -= 2;
            ry -= 2;
            continue;
        }
        col42(lx, ly);
        col33(lx, ly + 2);
        for (int i = ly + 5; i + 4 <= ry; i += 4) {
            col24(lx, i);
        }
        for (int i = lx + 7; i + 2 <= rx; i += 2) {
            col24(i, ly);
        }
        for (int i = lx + 5; i + 2 <= rx; i += 2) {
            col24(i, ry - 2);
        }
        collll33(lx + 4, ly);
        colrrr33(lx + 2, ry - 3);
        colw1(lx + 3, ly + 2);
        for (int i = ly + 4; i <= ry - 5; i += 2) {
            colw2(lx + 2, i);
        }
        lx += 6;
        ly += 4;
        ry -= 2;
        continue;
    }
    col33(lx, ly);
    print();
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }

    return 0;
}
    

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3
4

output:

2
1 2 2
2 1 2
1 1 0
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: 197ms
memory: 6708kb

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:

2
1
0
0 0
0 0
2
1 2 2
2 1 2
1 1 0
4
1 1 2 2
1 2 1 2
3 3 4 4
3 4 3 4
5
1 2 2 0 0
2 1 2 5 5
1 1 5 0 5
3 3 4 4 0
3 4 3 4 0
8
1 1 2 2 7 7
1 2 1 2 7 8
3 3 4 4 8 7
3 4 3 4 8 8
5 5 6 6 0 0
5 6 5 6 0 0
11
7 8 8 0 0 3 3
8 7 8 11 11 3 4
7 7 11 0 11 4 3
9 9 10 10 0 4 4
9 10 9 10 0 6 6
1 1 2 2 5 5 6
1 2 1 2 5 6...

result:

wrong answer Integer parameter [name=num] equals to 2, violates the range [0, 0] (test case 1)