QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#267054#7740. Puzzle: Question MarkValenciaTravisWA 236ms6112kbC++204.2kb2023-11-26 21:50:452023-11-26 21:50:46

Judging History

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

  • [2023-11-26 21:50:46]
  • 评测
  • 测评结果:WA
  • 用时:236ms
  • 内存:6112kb
  • [2023-11-26 21:50:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define MAXN 2005
int t, n, cnt;
int ans[MAXN][MAXN];

int three[4][3][3] = {
                      {{0, 1, 1},
                      {2, 2, 1},
                      {2, 1, 2}},

                      {{1, 1, 0},
                      {1, 2, 2},
                      {2, 1, 2}},

                      {{1, 1, 2},
                      {1, 2, 1},
                      {0, 2, 2}},

                      {{1, 2, 1},
                      {2, 1, 1},
                      {2, 2, 0}},
                      };

int four[4][4] = {{1, 1, 2, 2},
                  {1, 2, 4, 2},
                  {3, 1, 3, 4},
                  {3, 3, 4, 4}};

int ver[2][4] = {{1, 1, 2, 2},
                 {1, 2, 1, 2}};
int hor[4][2] = {{1, 1},
                 {2, 1},
                 {1, 2},
                 {2, 2}};
int tmp[4][4][4] = {
                    {{1, 1, 0, 0},
                    {1, 2, 0, 0},
                    {0, 1, 2, 0},
                    {0, 2, 2, 0}},

                    {{0, 1, 1, 0},
                    {0, 2, 1, 0},
                    {2, 1, 0, 0},
                    {2, 2, 0, 0}},

                    {{1, 1, 0, 0},
                    {1, 2, 1, 2},
                    {0, 0, 2, 2},
                    {0, 0, 0, 0}},

                    {{0, 0, 2, 2},
                    {1, 2, 1, 2},
                    {1, 1, 0, 0},
                    {0, 0, 0, 0}},
                   
                   };

void place3(int x, int y, int d){
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) 
        if(three[d][i][j]) ans[x+i][y+j] = cnt + three[d][i][j];
    cnt += 2;
}
void place4(int x, int y){
    for(int i=0;i<4;i++) for(int j=0;j<4;j++)
        ans[x+i][y+j] = cnt + four[i][j];
    cnt += 4;
}
void place24_ver(int x, int y){
    for(int i=0;i<2;i++) for(int j=0;j<4;j++)
        ans[x+i][y+j] = cnt + ver[i][j];
    cnt += 2;
}
void place24_hor(int x, int y){
    for(int i=0;i<4;i++) for(int j=0;j<2;j++)
        ans[x+i][y+j] = cnt + hor[i][j];
    cnt += 2;
}
void place24(int x, int y, int d){
    for(int i=0;i<4;i++) for(int j=0;j<4;j++) 
        if(tmp[d][i][j]) ans[x+i][y+j] = cnt + tmp[d][i][j];
    cnt += 2;
}

void solve0(int n){
    for(int i=1;i<=n;i+=4) for(int j=1;j<=n;j+=4) place4(i, j); 
}
void solve2(int n){
    solve0(n-2);
    int x = n/4*4+1;
    for(int i=1;i<=n-2;i+=4) place24_ver(x, i), place24_hor(i, x);
}
void solve1(int l, int r){
    if(r-l+1 == 9){
        place24_hor(1, l);
        place3(5, l, 1);
        place24_ver(8, l);
        place3(1, l+2, 3);
        place24(4, l+2, 0);
        place24_ver(1, l+5);
        place3(3, l+4, 1);
        place24_hor(3, l+7);
        place24(6, l+4, 1);
        place3(7, l+6, 0);
        return;
    }
    int len = r-l+1;
    for(int i=1;i<=n-5;i+=4) place24_hor(i, l), place24_hor(i, r-1);
    place24(len-4, l, 2);
    place3(len-2, l, 1);
    for(int i=l+4;i<=r-5;i+=4) place24_ver(len-3, i), place24_ver(len-1, i-1);
    place24(len-3, r-5, 1);
    place24_ver(len-1, r-3);
    place3(len-4, r-2, 0);
    solve1(l+2, r-2);
}
void solve3(int n){
    solve1(1, n-2);
    int x = n/4*4+2;
    for(int i=1;i<=n-3;i+=4) place24_ver(x, i), place24_hor(i, x);
    place3(n-2, n-2, 0);
}
void solve5(){
    place24_hor(1, 1);
    place3(1, 3, 0);
    ++cnt;
    ans[5][3] = ans[5][5] = ans[4][4] = ans[4][5] = cnt;
}
void solve7(){
    place3(1, 1, 3);
    place24_hor(4, 1);
    place24(1, 3, 1);
    place24_hor(1, 6);
    place3(5, 5, 0);
    ++cnt;
    ans[5][3] = ans[6][4] = ans[7][3] = ans[7][4] = cnt;
}

void work(){
    scanf("%d", &n);
    cnt = 0;
    if(n == 1) return (void)puts("0\n0");
    if(n == 2) return (void)puts("0\n0 0\n0 0\n");
    if(n == 3) place3(1, 1, 0);
    else if(n % 4 == 0) solve0(n);
    else if(n % 4 == 2) solve2(n);
    else if(n == 5) solve5();
    else if(n % 4 == 1) solve1(1, n);
    else if(n == 7) solve7();
    else if(n % 4 == 3) solve3(n);

    printf("%d\n", cnt);
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) printf("%d%c", ans[i][j], " \n"[j==n]);
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans[i][j] = 0;
}
int main(){
    cin>>t;
    while(t--) work();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3624kb

input:

2
3
4

output:

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

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 236ms
memory: 6112kb

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

result:

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