QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#223409 | #2921. Land Equality | rlong | WA | 0ms | 3712kb | C++17 | 2.0kb | 2023-10-22 03:18:00 | 2023-10-22 03:18:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int cnts[10];
for(int i=0;i<=2;i++) cnts[i] = 0;
int pw2[65];
pw2[0] = 1;
for(int i=1;i<=64;i++) pw2[i] = 2 * pw2[i-1];
int n, m;
cin >> n >> m;
int grid[n+5][m+5];
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
cin >> grid[i][j];
cnts[grid[i][j]]++;
}
}
if(n == 1) {
if(cnts[0] >= 2) cout << "0" << endl;
else if(cnts[0] == 1 && grid[1][1] != 0 && grid[1][m] != 0) {
cout << min(grid[1][1], grid[1][m]) << endl;
}
else if(cnts[0] == 1 && grid[1][1] == 0) {
cout << grid[1][m] << endl;
}
else if(cnts[0] == 1 && grid[1][m] == 0) {
cout << grid[1][1] << endl;
}
else { // only 1s and 2s
int lo = cnts[2] / 2;
int hi = cnts[2] - lo;
cout << pw2[hi] - pw2[lo] << endl;
}
}
else if(m == 1) {
if(cnts[0] >= 2) cout << "0" << endl;
else if(cnts[0] == 1 && grid[1][1] != 0 && grid[n][1] != 0) {
cout << min(grid[1][1], grid[n][1]) << endl;
}
else if(cnts[0] == 1 && grid[1][1] == 0) {
cout << grid[n][1] << endl;
}
else if(cnts[0] == 1 && grid[n][1] == 0) {
cout << grid[1][1] << endl;
}
else { // only 1s and 2s
int lo = cnts[2] / 2;
int hi = cnts[2] - lo;
cout << pw2[hi] - pw2[lo] << endl;
}
}
else {
if(cnts[0] >= 2) cout << "0" << endl;
else if(cnts[0] == 1 && cnts[1] > 0) cout << "1" << endl;
else if(cnts[0] == 1 && cnts[2] > 0) cout << "2" << endl;
else { // only 1s and 2s
int lo = cnts[2] / 2;
int hi = cnts[2] - lo;
cout << pw2[hi] - pw2[lo] << endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
1 2 0 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 2 0 2
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
1 2 1 2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
2 1 1 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
2 1 0 0
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 5 2 2 2 2 2 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 2 2 2
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
5 5 2 2 2 2 2 2 2 1 2 2 2 1 1 1 2 2 2 1 1 2 2 2 2 2 2
output:
512
result:
ok single line: '512'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
2 3 0 1 2 1 1 2
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
2 6 0 2 2 1 2 2 1 1 1 1 2 2
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
4 4 2 2 2 2 2 1 2 2 2 0 2 2 2 2 2 2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 3 0 1 2
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 6 2 1 2 0 1 2
output:
2
result:
ok single line: '2'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 1 2 1 2 0 1 2
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
1 5 0 1 1 1 2
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 6 2 1 2 0 2 1
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
1 6 1 1 2 0 1 2
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
6 1 2 1 2 0 2 1
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
1 10 2 1 1 1 0 0 1 1 1 2
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
1 10 1 2 0 2 2 2 2 0 2 1
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 10 0 1 1 1 2 2 1 1 1 0
output:
0
result:
ok single line: '0'
Test #21:
score: -100
Wrong Answer
time: 0ms
memory: 3584kb
input:
8 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
output:
-2147483648
result:
wrong answer 1st lines differ - expected: '2147483648', found: '-2147483648'