QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620781#7325. Tube Master IIUrdAC ✓2ms3880kbC++172.2kb2024-10-07 21:12:142024-10-07 21:12:14

Judging History

This is the latest submission verdict.

  • [2024-10-07 21:12:14]
  • Judged
  • Verdict: AC
  • Time: 2ms
  • Memory: 3880kb
  • [2024-10-07 21:12:14]
  • Submitted

answer

#include <bits/stdc++.h>
#define ALL(v) begin(v), end(v)

using i64 = int64_t;

const int kMaxN = 105;

int n, m;
std::array<std::array<int, kMaxN>, kMaxN> c, a, b, vr, vc;
void Proc() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) std::cin >> c[i][j];
  }
  for (int i = 1; i <= n + 1; ++i) {
    for (int j = 1; j <= m; ++j) std::cin >> a[i][j];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m + 1; ++j) std::cin >> b[i][j];
  }
  for (int i = 1; i <= n + 1; ++i) {
    for (int j = 1; j <= m + 1; ++j) vr[i][j] = vc[i][j] = 0;
  }
  if (c[1][1] == 4) vr[1][1] = vc[1][1] = 1;
  for (int i = 2; i <= m; ++i) {
    if (vr[1][i - 1]) {
      vc[1][i] = 1;
    } else {
      if (c[1][i] > 2) vc[1][i] = vr[1][i] = 1;
    }
  }
  vc[1][m + 1] = vr[1][m];
  for (int i = 2; i <= n + 1; ++i) {
    for (int j = 1; j <= m; ++j) {
      vr[i][j] = c[i - 1][j] - vr[i - 1][j] - vc[i - 1][j] - vc[i - 1][j + 1];
      if (vr[i][j] < 0 || vr[i][j] > 1) return void(std::cout << "-1\n");
    }
    if (i == n + 1) break;
    for (int j = 1; j <= m + 1; ++j) {
      vc[i][j] = (vc[i - 1][j] + vr[i][j - 1] + vr[i][j]) & 1;
    }
  }
  for (int i = 1; i <= n + 1; ++i) {
    for (int j = 1; j <= m + 1; ++j) {
      int cnt = vr[i][j] + vr[i][j - 1] + vc[i][j] + vc[i - 1][j];
      if (cnt != 0 && cnt != 2) return void(std::cout << "-1\n");
    }
  }
  for (int i = 1; i <= n + 1; ++i) {
    for (int j = 1; j <= m + 1; ++j) {
      if (j < m && vr[i][j] && vr[i][j + 1]) return void(std::cout << "-1\n");
      if (i < n && vc[i][j] && vc[i + 1][j]) return void(std::cout << "-1\n");
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (vr[i][j] + vc[i][j] + vr[i + 1][j] + vc[i][j + 1] != c[i][j]) {
        return void(std::cout << "-1\n");
      }
    }
  }
  i64 ans = 0;
  for (int i = 1; i <= n + 1; ++i) {
    for (int j = 1; j <= m + 1; ++j) {
      ans += vr[i][j] * a[i][j] + vc[i][j] * b[i][j];
    }
  }
  std::cout << ans << '\n';
}

auto main() -> int {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr), std::cout.tie(nullptr);
  while (std::cin >> n >> m) Proc();
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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

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

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

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

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: 0ms
memory: 3880kb

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: 0ms
memory: 3744kb

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

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

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

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

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: 2ms
memory: 3744kb

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

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

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