QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128708#5953. Checkerboard MatrixLinshey13 ✓72ms38976kbC++141.6kb2023-07-21 15:02:262023-07-21 15:19:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 15:19:56]
  • 评测
  • 测评结果:13
  • 用时:72ms
  • 内存:38976kb
  • [2023-07-21 15:02:26]
  • 提交

answer


#include <bits/stdc++.h>

using namespace std; const int maxn = 2e3 + 5;

int n;

char A[maxn][maxn];

int a[maxn][maxn], b[maxn][maxn];

int ans;

int c[maxn];

void work()
{
    for (int i = 1; i <= n << 1; i++)
    {
        int s = 0;
        for (int j = 1; j <= n << 1; j++) s += a[i][j];
        // cerr << s << endl;
        if (s != n)
        {
            ans += maxn << 1;
            return;
        }
    }
    for (int i = 1; i <= n << 1; i++)
    {
        bool A = 1, B = 1;
        for (int j = 1; j <= n << 1; j++) A &= (a[1][j] == a[i][j]);
        for (int j = 1; j <= n << 1; j++) B &= (a[1][j] != a[i][j]);
        if (!(A ^ B))
        {
            ans += maxn << 1;
            return;
        }
        c[i] = A;
    }
    int P = 0, Q = 0;
    for (int i = 1; i <= n << 1; i++) P += (c[i] == (i & 1));
    for (int i = 1; i <= n << 1; i++) Q += (c[i] != (i & 1));
    ans += (min(P, Q) >> 1);
}

inline void solve()
{
    scanf("%d", &n);
    for (int i = 1; i <= n << 1; i++)
    {
        scanf("%s", A[i] + 1);
        for (int j = 1; j <= n << 1; j++) a[i][j] = A[i][j] - '0';
    }
    ans = 0;
    work();
    for (int i = 1; i <= n << 1; i++) for (int j = 1; j <= n << 1; j++) b[i][j] = a[i][j];
    for (int i = 1; i <= n << 1; i++) for (int j = 1; j <= n << 1; j++) a[i][j] = b[j][i];
    work();
    if (ans >= maxn << 1) puts("IMPOSSIBLE");
    else printf("%d\n", ans);
}

int main()
{
    int Tt; scanf("%d", &Tt); for (int i = 1; i <= Tt; i++) printf("Case #%d: ", i), solve();
    return 0;
}

詳細信息

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 2ms
memory: 7776kb

input:

100
1
01
10
3
100110
100110
011001
011001
011001
100110
1
01
10
4
10110100
01101011
11100000
10110100
10110000
00001011
01001011
01001011
2
1010
1010
0101
0101
1
01
10
4
10001101
11010100
11000110
00111001
00101011
11010010
01100110
00111001
1
01
10
4
10110010
01100101
01101100
10010011
01101100
100...

output:

Case #1: 0
Case #2: 2
Case #3: 0
Case #4: IMPOSSIBLE
Case #5: 1
Case #6: 0
Case #7: IMPOSSIBLE
Case #8: 0
Case #9: IMPOSSIBLE
Case #10: 0
Case #11: IMPOSSIBLE
Case #12: 4
Case #13: IMPOSSIBLE
Case #14: 0
Case #15: IMPOSSIBLE
Case #16: IMPOSSIBLE
Case #17: 2
Case #18: 0
Case #19: IMPOSSIBLE
Case #20:...

result:

ok 100 lines

Subtask #2:

score: 9
Accepted

Test #2:

score: 9
Accepted
time: 72ms
memory: 38976kb

input:

100
82
01010110000101111001101100010110101011110011101100001000101000011100111001010110111000000110110010000110110010110010010010010010101100111001001100111111110100101011
01010110000101111001101100010110101011110011101100001000101000011100111001010110111000000110110010000110110010110010010010010010...

output:

Case #1: 73
Case #2: IMPOSSIBLE
Case #3: IMPOSSIBLE
Case #4: IMPOSSIBLE
Case #5: IMPOSSIBLE
Case #6: IMPOSSIBLE
Case #7: IMPOSSIBLE
Case #8: IMPOSSIBLE
Case #9: IMPOSSIBLE
Case #10: 67
Case #11: 76
Case #12: IMPOSSIBLE
Case #13: IMPOSSIBLE
Case #14: 31
Case #15: IMPOSSIBLE
Case #16: IMPOSSIBLE
Case ...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed