QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226555#7325. Tube Master IIPPPAC ✓2ms3864kbC++173.9kb2023-10-26 05:11:292023-10-26 05:11:29

Judging History

This is the latest submission verdict.

  • [2023-10-26 05:11:29]
  • Judged
  • Verdict: AC
  • Time: 2ms
  • Memory: 3864kb
  • [2023-10-26 05:11:29]
  • Submitted

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

typedef long long ll;
typedef long double ld;
int n, m;
const int maxN = 105;
int a[maxN][maxN];
int b[maxN][maxN];
int val_a[maxN][maxN];
int val_b[maxN][maxN];
int cnt[maxN][maxN];
void solve() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> cnt[i][j];
        }
    }

    for (int i = 1; i <= n + 1; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m + 1; j++) {
            cin >> b[i][j];
        }
    }
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= m + 1; j++) {
            val_a[i][j] = val_b[i][j] = 0;
        }
    }

    ll score = 0;
    if (cnt[1][1] == 4) {
        val_b[1][1] = 1;
        val_a[1][1] = 1;
    }
    else {
        val_b[1][1] = 0;
        val_a[1][1] = 0;
    }
    for (int i = 2; i <= m + 1; i++) {
        if (val_a[1][i - 1] == 1) {
            val_b[1][i] = 1;
            val_a[1][i] = 0;
        }
        else {
            if (i == m + 1) {
                val_b[1][i] = 0;
            }
            else {
                if (cnt[1][i] >= 3) {
                    val_b[1][i] = val_a[1][i] = 1;
                }
                else {
                    val_b[1][i] = val_a[1][i] = 0;
                }
            }
        }
    }
    for (int row = 2; row <= n + 1; row++) {
        for (int col = 1; col <= m; col++) {
            val_a[row][col] = cnt[row - 1][col] - val_a[row - 1][col] - val_b[row - 1][col] - val_b[row - 1][col + 1];
            if (val_a[row][col] < 0 || val_a[row][col] > 1) {
                cout << -1 << '\n';
                return;
            }
        }
        if (row == n + 1) break;
        for (int col = 1; col <= m + 1; col++) {
            val_b[row][col] = (val_b[row - 1][col] ^ val_a[row][col - 1]) ^ val_a[row][col];
        }
        val_b[row][1] = (val_b[row - 1][1] ^ val_a[row][1]);

    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int F = val_a[i + 1][j] + val_a[i][j] + val_b[i][j] + val_b[i][j + 1];
            if (F != cnt[i][j]) {
                cout << -1 << '\n';
                continue;
            }
        }
    }
    for (int i = 1; i <= n + 1; i++) {
        for (int j = 1; j <= m + 1; j++) {
            int X = val_a[i][j] + val_a[i][j - 1] + val_b[i - 1][j] + val_b[i][j];
            if (X != 0 && X != 2) {
                cout << -1 << '\n';
                return;
            }
        }
    }

    for (int i = 1; i <= n + 1; i++) {
        for (int j = 1; j + 1 <= m; j++) {
            if (val_a[i][j] && val_a[i][j + 1]) {
                cout << -1 << '\n';
                return;
            }
        }
    }


    for (int i = 1; i <= n - 1; i++) {
        for (int j = 1; j <= m + 1; j++) {
            if (val_b[i][j] && val_b[i + 1][j]) {
                cout << -1 << '\n';
                return;
            }
        }
    }

    for (int i = 1; i <= n + 1; i++) {
        for (int j = 1; j <= m; j++) {
            if (val_a[i][j] < 0 || val_a[i][j] > 1) {
                cout << -1 << '\n';
                return;
            }
            score += val_a[i][j] * a[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m + 1; j++) {
            if (val_b[i][j] < 0 || val_b[i][j] > 1) {
                cout << -1 << '\n';
                return;
            }
            score += val_b[i][j] * b[i][j];
        }
    }

    cout << score << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    while (cin >> n >> m) {
        solve();
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

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

output:

8
-1
79

result:

ok 3 number(s): "8 -1 79"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

10 8
4 1 0 1 4 1 0 1
1 1 0 0 1 0 1 4
2 3 2 0 0 1 0 1
3 0 3 1 1 4 1 1
2 3 2 1 0 2 1 4
0 1 1 4 2 4 1 2
0 0 0 2 0 1 1 4
0 0 1 4 1 0 0 1
1 0 0 1 0 0 0 1
4 1 0 0 0 0 1 4
2 2 2 1 1 2 1 2
1 1 2 1 1 1 1 1
1 2 1 2 1 2 1 1
1 2 1 1 1 1 2 2
1 1 2 1 2 1 2 1
2 2 2 2 1 1 2 1
1 1 1 2 2 1 1 2
1 2 1 2 2 1 2 2
2 1 2 2...

output:

83
-1
45
58
-1
20
-1
99
50
-1
74
50
54
84
45
-1
-1
65
92
-1
-1
-1
62
-1
-1
-1
76
71
-1
58
-1
-1
79
-1
-1
44
82
-1
-1
76
89
64
89
-1
-1
66
105
105
55
-1
34
69
-1
-1
72
-1
-1
-1
82
74
78
87
-1
76
57
-1
27
70
-1
25
63
-1
-1
-1
-1
-1
62
54
26
-1
75
97
58
-1
72
74
91
69
-1
-1
-1
-1
71
54
-1
38
-1
-1
31
57

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

10 10
4 1 0 1 0 0 0 1 4 1
1 0 2 3 2 0 0 1 1 0
1 1 3 0 3 1 1 2 1 0
4 1 2 3 2 0 0 2 0 0
1 0 1 1 0 0 1 4 1 1
0 1 4 1 1 0 1 1 1 4
1 0 1 1 4 2 4 1 0 2
4 1 0 0 1 0 1 0 1 4
1 0 1 0 0 1 0 0 0 1
0 1 4 1 1 4 1 0 0 0
637156111 681742660 510817373 111758656 948652630 538884415 983688457 17932881 647983164 35833...

output:

-1
-1
21043737050
30487902229
28640676011
27746623861
-1
29925798177
39716826059
-1
-1
28944654742
26641609969
-1
35488019300
-1
35455639372
29491925161
-1
37772627104
-1
26632046838
-1
34208411927
27995559776
-1
34048868167
-1
32255479111
33993240493
-1
29415752041
-1
-1
42199398158
33659861756
330...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3672kb

input:

10 10
1 0 3 4 1 0 0 1 4 1
4 1 0 1 0 0 0 1 1 0
2 0 0 0 0 0 1 4 1 1
4 1 1 0 0 0 0 1 1 4
1 1 4 1 1 0 1 0 0 1
0 0 1 1 4 2 4 1 0 0
0 0 0 1 1 1 1 0 1 0
0 0 1 4 2 4 1 1 4 1
0 0 1 1 0 1 1 0 1 0
0 1 4 1 0 1 4 1 0 0
191806095 578350621 94586148 878987116 116996379 772633727 993852293 946198 20267202 141986645...

output:

-1
38729623217
26951474101
-1
-1
-1
30736902461
-1
-1
23783565033
-1
-1
-1
28297033847
-1
33949739466
26384109782
-1
23494204405
-1
28232662888
-1
25982996014
-1
-1
27483619681
-1
29502099525
-1
36816896988
-1
-1
-1
-1
-1
-1
-1
32745875186
37023158077
-1
39920936837
-1
28652554066
28353666251
297520...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

20 20
0 0 1 4 1 0 1 4 1 0 0 0 1 4 1 0 1 0 1 0
1 0 1 1 0 0 0 2 0 0 0 1 0 1 0 1 4 2 4 1
4 2 4 1 0 0 1 4 1 0 1 4 1 0 0 0 1 0 1 0
1 1 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1
1 4 1 0 1 4 1 1 0 0 0 0 1 0 1 4 1 1 1 4
0 1 0 0 0 1 1 4 1 1 0 2 3 2 0 1 2 3 2 1
0 0 0 1 0 0 1 1 1 4 2 3 0 3 1 2 2 1 2 2
0 0 1 4 1 1 4 ...

output:

124471183206
119629714411
-1
113995452944
115221644821
131909608891
116607647478
116187304346
129457421816
144776681477
124010517973
125710522181
106834361597
117958058575
-1
122344422932
-1
108953950604
131122674161
-1

result:

ok 20 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 3624kb

input:

20 20
0 0 0 1 4 1 1 0 1 0 0 0 0 1 0 0 0 0 1 4
0 0 0 0 1 1 4 2 4 1 0 0 1 4 1 0 0 0 0 2
1 0 0 0 1 0 1 0 2 0 0 0 1 1 1 0 1 0 1 4
4 1 0 1 4 1 0 2 3 2 0 1 4 2 4 2 4 1 0 1
1 0 0 0 1 0 1 3 0 2 2 0 1 0 1 0 1 0 0 1
0 0 0 0 0 1 0 3 1 0 3 1 0 0 0 0 0 0 1 4
1 0 0 0 2 3 3 2 0 2 2 0 1 0 0 0 1 0 0 1
4 1 0 1 3 0 2 ...

output:

116878766878
139481018915
138683965076
106949575711
-1
-1
133342410506
-1
140630920056
-1
133472886210
138646438173
122448410426
123175492511
98292343995
96092277317
135630994923
-1
123612073471
-1

result:

ok 20 numbers

Test #7:

score: 0
Accepted
time: 2ms
memory: 3744kb

input:

50 50
0 1 1 4 2 4 1 0 0 1 4 2 4 2 4 2 4 1 1 4 1 1 0 1 4 1 0 0 1 4 1 1 0 0 0 1 4 1 1 4 1 0 1 4 1 1 4 2 4 1
1 4 1 1 0 2 0 0 0 0 1 1 1 0 2 0 2 0 0 1 1 4 1 0 2 0 0 0 0 1 1 4 1 0 0 0 1 0 0 1 0 0 0 2 0 1 1 1 1 1
0 1 0 1 1 4 1 1 0 1 1 4 1 1 4 2 4 1 0 0 0 2 0 2 3 2 0 0 0 1 0 2 0 1 0 0 0 1 0 0 0 0 1 4 2 4 2 ...

output:

-1
724635164718
-1
757490227929

result:

ok 4 number(s): "-1 724635164718 -1 757490227929"

Test #8:

score: 0
Accepted
time: 2ms
memory: 3704kb

input:

50 50
4 2 4 1 0 1 0 0 0 1 1 4 1 0 0 0 0 0 1 4 1 1 4 2 4 1 1 1 4 1 1 4 2 4 2 4 1 1 4 1 0 1 4 1 0 0 0 2 3 2
1 0 1 0 2 3 2 0 2 3 2 1 0 0 0 0 0 0 0 1 0 0 1 1 1 2 3 2 1 0 0 1 0 1 0 1 1 0 2 0 0 0 1 0 0 0 1 3 0 3
0 0 0 1 3 0 3 2 3 0 3 1 0 1 0 0 0 0 0 0 0 0 1 4 2 3 0 3 1 0 1 0 0 0 0 1 4 2 4 1 1 0 0 0 0 0 0 ...

output:

772073639665
-1
734515479069
723004704873

result:

ok 4 number(s): "772073639665 -1 734515479069 723004704873"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3768kb

input:

100 100
4 2 4 1 2 3 2 0 0 1 4 1 1 1 4 2 4 1 1 4 1 0 0 0 0 1 4 1 1 4 1 0 1 4 1 0 0 0 0 0 0 1 4 1 0 1 0 1 0 1 0 1 0 0 1 0 1 4 1 1 4 1 1 4 1 1 1 4 1 1 4 1 0 1 4 1 0 0 1 4 2 4 1 1 4 1 1 1 4 1 1 1 4 2 4 1 1 4 2 4
1 1 1 2 2 0 2 2 0 0 1 1 4 1 2 0 2 0 0 1 0 1 0 0 0 1 1 1 0 2 0 0 1 1 0 0 0 0 1 0 0 0 1 1 1 4 ...

output:

2814404110082

result:

ok 1 number(s): "2814404110082"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3772kb

input:

100 100
0 1 4 1 1 4 1 1 1 4 1 2 3 3 3 2 0 0 1 0 0 1 1 4 1 1 0 0 1 1 4 2 4 1 0 1 1 4 1 2 3 2 0 0 0 1 4 2 4 2 4 2 4 1 1 0 0 1 4 1 1 1 4 2 4 1 0 0 0 0 0 2 3 2 1 4 2 4 2 4 1 0 0 0 2 3 2 0 2 3 3 3 2 1 4 1 0 0 1 4
0 0 1 0 1 1 1 4 1 2 1 3 0 1 0 2 2 1 4 1 2 3 2 1 1 4 1 1 4 1 2 0 1 0 1 4 1 2 1 3 0 3 1 0 1 0 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #11:

score: 0
Accepted
time: 2ms
memory: 3864kb

input:

100 100
1 4 2 4 1 0 2 3 3 3 3 3 2 0 0 0 2 3 3 3 3 3 2 0 1 4 1 0 1 1 4 2 4 1 1 0 0 0 1 4 1 0 1 0 1 4 1 2 3 2 1 4 1 0 1 1 4 1 0 0 0 0 2 3 2 0 1 4 1 2 3 2 1 4 2 4 1 0 0 0 1 4 1 1 1 4 1 0 0 0 1 1 4 1 1 4 1 0 0 0
0 2 0 2 0 1 3 0 1 1 1 0 3 1 0 2 2 0 1 0 1 0 3 1 1 1 0 1 4 1 1 1 1 1 4 1 0 0 0 1 0 1 4 1 0 1 ...

output:

3005112707429

result:

ok 1 number(s): "3005112707429"

Test #12:

score: 0
Accepted
time: 2ms
memory: 3844kb

input:

100 100
0 2 3 2 1 4 2 4 1 0 1 0 0 1 4 1 1 1 4 1 1 4 1 1 0 2 3 3 3 2 0 1 1 4 1 0 0 1 0 1 4 1 0 1 0 0 1 0 1 4 2 4 1 0 0 2 3 2 0 0 1 4 1 1 0 1 0 0 0 1 4 1 0 1 1 4 1 1 4 1 0 2 3 2 0 0 0 2 3 2 0 1 4 1 1 4 1 1 4 1
1 3 0 3 1 1 0 1 1 1 4 1 0 0 1 1 4 1 1 0 1 1 1 4 2 3 0 1 0 2 3 3 2 1 0 0 1 4 1 0 2 0 1 4 1 1 ...

output:

2774288286857

result:

ok 1 number(s): "2774288286857"

Test #13:

score: 0
Accepted
time: 2ms
memory: 3836kb

input:

100 100
1 4 1 1 4 1 1 1 4 1 1 0 0 0 1 4 1 0 1 4 1 0 0 1 4 2 4 2 4 2 4 2 4 1 2 3 2 1 4 1 0 0 1 0 0 0 0 0 1 4 1 0 1 1 4 1 0 0 1 4 2 4 1 1 1 4 1 0 1 4 1 0 1 4 2 4 1 0 1 4 1 0 0 1 0 1 4 1 0 0 0 0 0 0 0 1 4 1 1 4
1 1 0 0 1 1 4 1 2 1 4 1 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 1 1 0 1 0 1 1 3 0 3 1 1 0 0 2 3 2 0 0 ...

output:

2929594083311

result:

ok 1 number(s): "2929594083311"

Test #14:

score: 0
Accepted
time: 2ms
memory: 3792kb

input:

100 100
4 1 0 1 4 2 4 2 4 2 4 2 4 1 0 0 1 4 1 0 0 0 0 1 4 2 4 1 0 0 0 0 1 4 2 4 1 0 1 0 1 0 1 4 1 1 4 1 1 4 1 1 4 1 0 0 0 0 1 0 1 4 1 1 4 2 4 2 4 1 1 4 1 0 0 0 0 2 3 2 0 1 4 1 1 4 1 1 4 1 0 1 0 1 1 4 2 4 2 4
1 1 0 1 1 0 2 0 1 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 4 2 4 1 0 1 0 0 ...

output:

-1

result:

ok 1 number(s): "-1"

Test #15:

score: 0
Accepted
time: 2ms
memory: 3832kb

input:

100 100
0 0 1 4 1 1 4 2 4 1 1 0 0 0 1 4 1 0 0 0 1 4 2 4 1 0 1 4 1 0 0 0 0 1 4 1 1 4 1 0 0 1 0 0 1 0 1 0 0 0 1 4 1 0 0 0 0 0 0 1 4 1 1 0 1 1 4 2 4 1 0 0 0 0 0 1 4 2 4 1 0 0 0 1 4 1 2 3 2 1 4 2 4 2 4 1 0 1 4 1
1 0 0 1 0 0 1 0 1 1 4 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 1 0 2 0 0 2 0 0 1 4 1 2 3 3 ...

output:

2872793340511

result:

ok 1 number(s): "2872793340511"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3796kb

input:

100 100
1 1 4 1 1 0 1 1 4 2 4 1 1 1 4 1 1 0 0 0 1 1 4 1 0 1 0 0 1 1 4 1 0 0 1 1 4 1 2 3 3 3 2 0 0 0 1 0 1 4 1 2 3 3 3 3 3 2 1 4 2 4 1 0 1 0 2 3 2 0 0 1 4 2 4 1 0 0 0 0 0 1 4 2 4 1 1 0 0 1 0 1 0 1 0 1 4 1 1 4
4 1 1 2 3 3 3 2 1 1 1 1 4 1 2 1 4 1 0 1 4 1 2 0 2 3 2 1 4 1 1 0 0 1 4 1 1 1 3 0 1 0 3 1 0 1 ...

output:

2949049518176

result:

ok 1 number(s): "2949049518176"

Test #17:

score: 0
Accepted
time: 2ms
memory: 3792kb

input:

100 100
1 4 2 4 1 0 0 0 0 1 4 1 0 0 1 4 2 4 1 2 3 2 0 1 4 1 1 4 1 0 0 1 4 1 1 4 2 4 1 1 4 1 0 0 1 0 0 1 4 2 4 2 4 2 4 1 1 4 1 1 4 2 4 1 0 1 0 0 1 0 0 0 1 4 2 4 1 1 4 1 0 1 1 4 1 0 1 0 1 4 2 4 2 4 2 4 1 0 0 0
0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 1 3 0 3 1 0 1 0 1 1 0 0 0 0 1 0 0 2 0 1 0 0 1 0 0 2 3 2 ...

output:

2781178252547

result:

ok 1 number(s): "2781178252547"

Test #18:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

100 100
4 1 1 4 2 4 1 1 0 0 1 0 1 4 2 4 1 0 0 1 4 2 4 1 2 3 3 3 3 3 2 0 1 4 2 4 2 4 2 4 2 4 2 4 1 1 4 1 0 1 4 1 1 1 4 2 4 1 0 1 4 1 0 0 1 0 0 0 0 0 0 0 0 1 4 2 4 2 4 1 2 3 2 0 1 4 1 1 4 1 1 0 1 0 0 0 0 1 4 1
1 0 0 1 0 1 1 4 1 1 4 1 0 1 0 1 0 0 0 0 1 0 1 2 2 0 1 0 1 0 2 2 0 2 0 2 0 2 0 1 0 1 0 1 0 0 ...

output:

-1

result:

ok 1 number(s): "-1"

Extra Test:

score: 0
Extra Test Passed