QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90759 | #94. Good Old Table | snpmrnhlol | WA | 420ms | 12184kb | C++14 | 2.3kb | 2023-03-25 07:49:15 | 2023-03-25 07:49:16 |
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 == 0){
for(j = 0;j < m;j++)lines[j]++;
lines[0]--;
}
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);
/*for(j = 0;j < m;j++){
cout<<lines[j]<<' ';
}*/
int sum = 0,ans = 2e9;
for(i = m-1;i >= 0;i--)sum+=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;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 420ms
memory: 12184kb
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: 379ms
memory: 12092kb
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: 392ms
memory: 12080kb
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: 399ms
memory: 12144kb
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: 396ms
memory: 12080kb
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: -100
Wrong Answer
time: 81ms
memory: 10588kb
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:
300732
result:
wrong answer 1st numbers differ - expected: '299224', found: '300732'