QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#726169 | #2921. Land Equality | zeyu# | AC ✓ | 0ms | 3828kb | C++23 | 2.4kb | 2024-11-08 22:06:41 | 2024-11-08 22:06:42 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif
const ll mod = 1e9 + 7;
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
int a[n][m];
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++) cin >> a[i][j];
}
vector<int> cnt(3);
for (int i = 0; i < n; i ++){
for (int j = 0; j < m; j ++) cnt[a[i][j]] ++;
}
if (cnt[0]){
if (cnt[0] > 1) cout << 0;
else{
if (n == 1){
int ans = 2;
if (a[0][0] != 0) chkmin(ans, a[0][0]);
if (a[0][m - 1] != 0) chkmin(ans, a[0][m - 1]);
cout << ans;
} else if (m == 1){
int ans = 2;
if (a[0][0] != 0) chkmin(ans, a[0][0]);
if (a[n - 1][0] != 0) chkmin(ans, a[n - 1][0]);
cout << ans;
} else{
if (cnt[1]) cout << 1;
else cout << 2;
}
}
} else{
if (cnt[2] % 2 == 0) cout << 0;
else cout << (1ll << (cnt[2] / 2));
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
1 2 0 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1 2 0 2
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
1 2 1 2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
2 1 1 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
2 1 0 0
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3824kb
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: 3820kb
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: 3476kb
input:
2 3 0 1 2 1 1 2
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3476kb
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: 3552kb
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: 3524kb
input:
1 3 0 1 2
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
1 6 2 1 2 0 1 2
output:
2
result:
ok single line: '2'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
6 1 2 1 2 0 1 2
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
1 5 0 1 1 1 2
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
1 6 2 1 2 0 2 1
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 6 1 1 2 0 1 2
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
6 1 2 1 2 0 2 1
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3528kb
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: 3476kb
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: 3824kb
input:
1 10 0 1 1 1 2 2 1 1 1 0
output:
0
result:
ok single line: '0'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3544kb
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:
ok single line: '2147483648'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
0
result:
ok single line: '0'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
8 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
0
result:
ok single line: '0'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3608kb
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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
7 9 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
output:
2147483648
result:
ok single line: '2147483648'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
31 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
output:
0
result:
ok single line: '0'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 61 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
output:
1073741824
result:
ok single line: '1073741824'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
8 8 1 0 0 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 1 0
output:
0
result:
ok single line: '0'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
6 10 0 0 0 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 1 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 1 0 0 0
output:
0
result:
ok single line: '0'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
8 8 2 0 2 2 2 2 2 2 0 2 0 0 0 2 2 2 0 2 2 0 2 2 0 0 0 2 2 2 0 2 0 2 2 2 0 2 0 0 2 0 0 2 0 2 2 0 2 2 0 2 0 0 2 0 2 2 2 2 2 0 0 0 2 2
output:
0
result:
ok single line: '0'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
10 6 2 0 2 2 0 2 0 0 2 2 0 2 2 2 0 2 0 2 2 2 2 0 2 0 0 0 2 0 0 2 2 2 2 0 2 2 2 0 0 0 2 0 2 2 0 2 0 0 0 2 2 2 0 0 0 0 0 2 2 0
output:
0
result:
ok single line: '0'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
8 8 1 1 2 1 2 1 1 1 1 2 1 1 2 2 1 1 2 2 1 2 1 2 2 1 1 1 2 2 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 2 2 2 1 1
output:
8192
result:
ok single line: '8192'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
7 9 2 2 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 1 1 1 1 2 1 1 2 2 2 2 1 2 2 1 2 2 2 2 2 1 1 1 2 1
output:
65536
result:
ok single line: '65536'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
9 7 2 1 1 1 2 1 2 2 2 1 2 2 1 2 2 1 1 2 1 1 2 1 2 2 2 2 1 2 1 1 1 1 2 2 2 1 2 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 2 1 1 2 1 1
output:
65536
result:
ok single line: '65536'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
8 8 2 1 0 0 2 1 2 2 1 0 0 1 1 0 2 0 1 0 1 2 0 1 0 2 1 2 1 2 1 2 1 2 0 0 1 2 1 0 0 2 0 0 2 1 2 0 2 1 2 1 1 1 1 0 2 0 0 0 1 2 0 1 1 0
output:
0
result:
ok single line: '0'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
7 9 1 1 1 0 2 1 1 2 0 2 1 2 2 2 2 2 0 1 2 0 2 2 0 1 2 0 2 0 2 2 0 0 2 1 1 2 0 0 1 1 1 1 0 1 1 1 2 0 1 1 0 1 1 0 0 2 0 1 2 2 0 0 2
output:
0
result:
ok single line: '0'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
9 7 2 2 0 2 2 1 2 2 0 2 0 1 1 1 2 1 1 0 1 0 2 0 0 0 1 1 0 1 1 2 1 2 2 2 0 1 2 0 0 0 0 2 1 2 1 0 1 2 2 0 2 2 2 2 0 2 2 0 2 0 2 0 1
output:
0
result:
ok single line: '0'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 64 0 2 1 2 0 1 2 0 2 1 1 2 2 2 2 2 1 2 2 1 2 0 0 1 2 1 1 0 0 2 0 1 1 1 1 1 2 1 2 1 2 0 2 2 0 0 1 1 2 2 1 1 1 1 0 0 2 1 2 2 2 0 2 1
output:
0
result:
ok single line: '0'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
64 1 1 1 0 0 1 2 0 1 0 1 0 2 2 2 0 2 1 1 2 1 0 0 2 0 0 1 2 0 1 0 0 2 1 1 0 2 2 0 2 0 1 0 0 1 2 1 0 1 1 2 2 0 1 1 0 0 0 0 2 0 2 1 1 2
output:
0
result:
ok single line: '0'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
2 32 0 2 2 2 2 1 1 1 2 1 1 2 1 1 2 0 1 1 2 2 2 2 0 0 0 0 0 1 2 1 0 2 0 1 2 2 2 1 1 1 0 0 1 2 2 2 0 0 0 1 1 2 0 0 1 2 2 0 0 2 2 0 2 0
output:
0
result:
ok single line: '0'
Test #41:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
32 2 1 0 1 2 2 0 0 1 0 0 0 2 1 0 1 1 0 2 1 0 1 1 2 0 1 1 1 2 2 0 1 1 0 0 2 0 2 1 1 2 0 2 2 0 0 1 1 2 0 1 1 1 1 1 0 0 2 2 0 1 0 0 2 0
output:
0
result:
ok single line: '0'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 63 1 1 1 2 0 1 1 1 2 1 1 1 2 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 2 2 1 2 2 1 1 2 2 2 1 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 2 1 1 1
output:
1
result:
ok single line: '1'
Test #43:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 64 1 2 1 2 2 1 1 1 0 2 1 1 2 1 2 2 2 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 1 1 2 2 2 1 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 2 2 1 2 1 2
output:
1
result:
ok single line: '1'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
63 1 1 1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 2 1 2 1 2 1 1 1 2 1 1 2 2 2 2 1 1 1 2 1 2 1 2 2 1 1 2 1 1 0 1 2 2 1 1 1 1
output:
1
result:
ok single line: '1'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
64 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 2 1 2 1 1 1 2 1 2 1 2 2 2 2 1 1 1 2 2 1 2 0 1 1 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 1 2 2 2 2 1 1 1 1 2
output:
2
result:
ok single line: '2'
Test #46:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
8 8 2 1 1 2 1 1 2 2 1 1 1 1 1 1 2 1 1 2 2 1 2 2 2 1 1 2 1 1 1 2 2 0 1 1 1 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 1 2 1 1 1 2 1 2 2 1 2 2
output:
1
result:
ok single line: '1'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
2 32 2 1 1 2 0 2 2 2 1 1 2 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 2 2 1 2 2 1 1 2 1 2 2 2 1 1 2 1 2 2 2 1 2 1 2 1 2 2
output:
1
result:
ok single line: '1'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
32 2 2 2 1 1 2 1 1 1 2 1 1 2 1 1 1 1 1 2 2 2 1 1 2 1 1 1 2 1 1 1 1 1 2 1 1 2 1 2 1 1 1 2 1 0 1 2 1 1 1 1 2 1 2 1 2 1 1 2 2 2 1 2 2 2
output:
1
result:
ok single line: '1'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 4 1 2 1 1 2 2 1 2 1 2 2 2
output:
8
result:
ok single line: '8'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
2 3 0 1 2 0 1 2
output:
0
result:
ok single line: '0'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
1 3 2 0 2
output:
2
result:
ok single line: '2'