QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#264962#7740. Puzzle: Question Markucup-team1198#WA 206ms6472kbC++202.8kb2023-11-25 16:12:362023-11-25 16:12:36

Judging History

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

  • [2023-11-25 16:12:36]
  • 评测
  • 测评结果:WA
  • 用时:206ms
  • 内存:6472kb
  • [2023-11-25 16:12:36]
  • 提交

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

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 % 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();
}

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: 3596kb

input:

2
3
4

output:

2
0 2 2
1 1 2
1 2 1
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: 206ms
memory: 6472kb

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 2 2
1 1 2
1 2 1
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 Jury has better answer. Participant 19, jury 20 (test case 9)