QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90761 | #94. Good Old Table | snpmrnhlol | AC ✓ | 506ms | 12260kb | C++14 | 3.2kb | 2023-03-25 08:04:35 | 2023-03-25 08:04:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool v[3000][3000];
int ps[3000],ps2[3000];
int lines[3000];
int main(){
int n,m,i,j,cnt = 0;
char ch;
cin>>n>>m;
if(m%2 == 1){
for(i = 0;i < n;i++)for(j = 0;j < m;j++){
cin>>ch;v[j][i] = ch - '1';
}
swap(n,m);
}else for(i = 0;i < n;i++)for(j = 0;j < m;j++){
cin>>ch;v[i][j] = ch - '1';
}
if(n == 1){
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
cnt+=v[i][j];
}
}
if(cnt == n*m){
cout<<1;
}else if(cnt == 0){
cout<<0;
}else cout<<-1;
}else if(n%2 == 0){
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
ps[i]+=v[i][j];
ps2[j]+=v[i][j];
}
}
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
cnt+=((ps[i] + ps2[j] + v[i][j])%2);
}
}
cout<<cnt;
}else{
bool ok = 1;
int cnt2 = 0;
for(i = 0;i < n;i++){
for(j = 0;j < m;j++){
if(i == n - 1){
cnt2+=(v[i][j] == cnt);
}else{
v[n - 1][j]^=v[i][j];
cnt+=v[i][j];cnt%=2;
ps[i]+=v[i][j];ps2[j]+=v[i][j];
}
}
}
if(cnt2 != 0 && cnt2 != m){
cout<<-1;
}else{
if(cnt2 == m){
for(i = 0;i < n - 1;i++){
for(j = 0;j < m;j++){
lines[j]+=(v[i][j]+ps[i]+ps2[j])%2;
}
}
sort(lines,lines + m);
int sum = 0,ans = 2e9;
for(i = m-1;i >= 0;i--)sum+=lines[i];//cout<<lines[i]<<' ';
ans = min(ans,sum);
for(i = m-1;i >= 0;i-=2){
sum-=lines[i];sum-=lines[i - 1];
lines[i] = n - lines[i];
lines[i - 1] = n - lines[i - 1];
sum+=lines[i];sum+=lines[i - 1];
ans = min(ans,sum);
}
cout<<ans;
}else{
for(i = 0;i < n - 1;i++){
for(j = 0;j < m;j++){
lines[j]+=(v[i][j]+ps[i]+ps2[j])%2;
}
}
for(j = 0;j < m;j++)lines[j]++;
sort(lines,lines + m);
int sum = 0,ans = 2e9;
for(i = m-1;i >= 0;i--)sum+=lines[i];
sum-=lines[m - 1];lines[m - 1] = n - lines[m - 1];sum+=lines[m - 1];
ans = min(ans,sum);
for(i = m-2;i >= 0;i-=2){
sum-=lines[i];sum-=lines[i - 1];
lines[i] = n - lines[i];
lines[i - 1] = n - lines[i - 1];
sum+=lines[i];sum+=lines[i - 1];
ans = min(ans,sum);
}
cout<<ans;
}
}
}
return 0;
}
/**
3 4
1 2 1 2
1 1 2 2
2 1 1 2
3 4
2 2 2 2
2 2 2 2
2 2 2 2
**/
詳細信息
Test #1:
score: 100
Accepted
time: 409ms
memory: 12100kb
input:
3000 3000 2 1 2 1 2 1 1 1 1 2 1 1 2 2 1 2 2 2 2 1 1 1 2 1 1 2 2 2 2 2 2 1 1 1 1 2 1 2 1 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 1 1 1 2 2 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 2 1 2 2 1 1 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 2 ...
output:
4499318
result:
ok 1 number(s): "4499318"
Test #2:
score: 0
Accepted
time: 427ms
memory: 12116kb
input:
3000 3000 1 2 2 2 1 2 2 1 1 1 2 1 2 1 2 2 2 1 2 1 1 2 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 2 2 1 1 2 2 1 2 2 1 2 2 2 1 2 1 1 1 2 2 1 2 1 2 1 2 2 1 2 2 1 1 2 2 1 2 2 2 2 2 1 1 2 2 2 1 1 1 1 2 2 1 1 2 1 1 2 1 1 1 1 2 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 2 1 2 2 1 2 1 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 1 2 2 2 1 2 ...
output:
4500268
result:
ok 1 number(s): "4500268"
Test #3:
score: 0
Accepted
time: 399ms
memory: 12096kb
input:
3000 3000 1 1 2 2 2 2 1 2 1 1 2 1 2 2 2 2 1 2 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 1 2 2 1 2 2 2 1 2 2 2 2 1 1 1 1 1 2 1 2 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 1 2 2 2 1 2 1 1 2 1 1 2 1 1 1 2 2 1 2 2 2 2 2 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 2 2 2 ...
output:
4499488
result:
ok 1 number(s): "4499488"
Test #4:
score: 0
Accepted
time: 388ms
memory: 12140kb
input:
3000 3000 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 409ms
memory: 12260kb
input:
3000 3000 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 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
9000000
result:
ok 1 number(s): "9000000"
Test #6:
score: 0
Accepted
time: 95ms
memory: 10552kb
input:
712 2467 2 1 2 2 2 2 2 2 2 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 2 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 2 2 2 1 1 1 1 1 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 1 1 1 2 2 2 2 2 2 1 2 1 1 1 1 1 2 2 2 1 2 2 2 2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 1 1 2 1 2 1 1 1 1 1 2 2 2 2 2...
output:
299224
result:
ok 1 number(s): "299224"
Test #7:
score: 0
Accepted
time: 24ms
memory: 5224kb
input:
842 643 1 1 2 1 2 1 2 1 2 1 2 2 1 1 2 2 2 2 2 1 1 1 2 1 1 1 2 1 2 2 1 2 1 1 1 1 1 2 2 1 1 1 1 1 2 1 2 1 2 2 2 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 1 1 1 2 2 1 1 2 2 2 2 2 1 2 1 2 1 1 1 1 1 2 1 2 1 1 1 2 2 2 1 1 1 1 1 1 2 2 1 2 2 2 2 1 1 2 1 2 1 1 1 2 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 1 1 1 2 1 ...
output:
184027
result:
ok 1 number(s): "184027"
Test #8:
score: 0
Accepted
time: 43ms
memory: 4860kb
input:
463 1850 2 1 1 2 2 1 2 1 1 1 1 1 1 1 2 1 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 1 2 1 2 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 2 1 2 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 2 1 1 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 2 1 2 1 1 1...
output:
411193
result:
ok 1 number(s): "411193"
Test #9:
score: 0
Accepted
time: 8ms
memory: 4068kb
input:
287 820 1 2 1 2 1 1 1 2 2 1 2 2 1 2 2 2 2 1 1 2 2 2 2 1 1 2 1 1 1 1 1 1 2 1 1 2 1 2 1 1 1 1 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 2 2 1 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 1 1 1 2 2 2 1 1 1 2 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 2 2 2 1 1 2 2 1 ...
output:
75191
result:
ok 1 number(s): "75191"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
109 160 2 2 1 2 1 1 2 2 1 1 1 1 2 2 2 2 1 2 1 1 2 2 2 1 1 1 1 2 2 1 1 2 1 1 2 1 2 2 2 1 2 2 1 2 2 2 2 2 2 1 1 2 1 1 1 1 2 1 1 2 1 1 1 2 1 2 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 2 1 1 1 1 2 1 2 1 1 1 2 1 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 2 1 2 1 2 2 1 ...
output:
2630
result:
ok 1 number(s): "2630"
Test #11:
score: 0
Accepted
time: 18ms
memory: 4972kb
input:
565 558 2 1 1 2 2 1 2 2 2 2 2 1 2 2 2 2 1 1 2 1 1 1 1 1 2 2 1 2 1 1 2 1 1 1 2 2 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 1 1 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 2 2 1 1 2 2 2 1 2 1 2 1 2 2 2 1 1 1 1 1 2 2 1 1 1 2 1 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 1 1 1 2 2 1 2 1 2 1 ...
output:
-1
result:
ok 1 number(s): "-1"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
1918 1 1 1 1 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 1 2 1 2 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 2 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 1 1 1 2 1 2 2 1 2 2 1 1 2 2 2 1 2 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 1 2 1 1 1 1 1 2 2 1 1 2 2 2 2 2 1 2 1 1 1 1 2 1 2 1 1 1 2 1 2 2 1 1 1 2 1 2 1 1 2...
output:
-1
result:
ok 1 number(s): "-1"
Test #13:
score: 0
Accepted
time: 2ms
memory: 8608kb
input:
1806 2 2 2 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 2 2 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 2 1 2 1 1 1 1 2 2 2 2 2 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 1 1 2 1 2 1 1 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 1 1 1 2 1 2 1 2 2 1 1 2 1 1 2 2 2 2 2 1 1 1 1 1 1 1 2 2...
output:
1758
result:
ok 1 number(s): "1758"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
1544 3 1 2 2 1 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 1 1 1 2 1 1 1 1 2 2 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 1 2 1 1 2 2 2 1 1 1 1 2 1 2 1 2 2 1 1 2 1 2 1 1 2 2 2 2 1 1 1 1 1 2 2 1 2 1 1 2 1 1 1 2 1 1 2 2 2 2 1 2 1...
output:
-1
result:
ok 1 number(s): "-1"
Test #15:
score: 0
Accepted
time: 2ms
memory: 3288kb
input:
3 2 2 1 2 1 1 1
output:
2
result:
ok 1 number(s): "2"
Test #16:
score: 0
Accepted
time: 2ms
memory: 3308kb
input:
4 1 2 2 2 2
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3232kb
input:
3 2 1 2 1 2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #18:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
1 2 1 1
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 2ms
memory: 3344kb
input:
3 2 1 2 1 2 1 1
output:
2
result:
ok 1 number(s): "2"
Test #20:
score: 0
Accepted
time: 429ms
memory: 12124kb
input:
3000 3000 1 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 2 2 2 1 2 1 1 2 1 1 2 1 1 2 1 1 1 2 2 1 1 1 1 2 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 1 2 1 1 2 2 2 2 1 2 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 2 2 1 2 2 1 1 1 1 2 1 2 1 2 2 2 1 1 1 1 1 2 2 1 2 2 1 1 1 1 1 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 2 1 ...
output:
4499996
result:
ok 1 number(s): "4499996"
Test #21:
score: 0
Accepted
time: 438ms
memory: 12144kb
input:
2999 3000 1 2 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 2 2 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 2 2 1 2 1 1 1 2 2 1 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 2 1 2 1 1 2 1 1 2 1 2 1 2 2 1 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 1 1 1 1 2 2 ...
output:
4423060
result:
ok 1 number(s): "4423060"
Test #22:
score: 0
Accepted
time: 506ms
memory: 12096kb
input:
3000 2999 2 2 2 1 2 1 1 2 2 1 1 2 1 1 2 1 1 2 2 1 2 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 2 2 2 1 2 2 2 2 1 1 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 2 1 1 1 1 1 2 2 2 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 1 1 1 2 2 2 2 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 1 1 1 2 1 2 2 2 1 1 2 2 2 2 2 1 1 2 1 1 2 2 1 ...
output:
4434271
result:
ok 1 number(s): "4434271"