QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90758#94. Good Old TablesnpmrnhlolWA 436ms12288kbC++142.2kb2023-03-25 07:36:412023-03-25 07:36:42

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-25 07:36:42]
  • 评测
  • 测评结果:WA
  • 用时:436ms
  • 内存:12288kb
  • [2023-03-25 07:36:41]
  • 提交

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]++;ps2[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);
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 409ms
memory: 12096kb

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: 398ms
memory: 12100kb

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: 420ms
memory: 12288kb

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: 436ms
memory: 12112kb

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: 406ms
memory: 12140kb

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: 84ms
memory: 10572kb

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:

861936

result:

wrong answer 1st numbers differ - expected: '299224', found: '861936'