QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90762#94. Good Old TablesnpmrnhlolWA 528ms10412kbC++112.4kb2023-03-25 08:17:322023-03-25 08:17:33

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 08:17:33]
  • 评测
  • 测评结果:WA
  • 用时:528ms
  • 内存:10412kb
  • [2023-03-25 08:17:32]
  • 提交

answer

#include <stdio.h>
#include <algorithm>
bool v[3000][3000];
int ps[3000],ps2[3000];
int lines[3000];
int main(){
    int n,m,i,j,cnt = 0,res;
    char ch;
    scanf("%d%d\n",&n,&m);
    if(m%2 == 1){
        for(i = 0;i < n;i++)for(j = 0;j < m;j++){
            scanf("%c",&ch);v[j][i] = ch - '1';
            scanf("%c",&ch);
        }
        res = n;n = m;m = res;
    }else for(i = 0;i < n;i++)for(j = 0;j < m;j++){
        scanf("%c",&ch);v[i][j] = ch - '1';
        scanf("%c",&ch);
    }
    if(n == 1){
        for(i = 0;i < n;i++){
            for(j = 0;j < m;j++){
                cnt+=v[i][j];
            }
        }
        if(cnt == n*m){
            printf("1");
        }else if(cnt == 0){
            printf("0");
        }else printf("-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);
            }
        }
        printf("%d",cnt);
    }else{
        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){
            printf("-1");
        }else{
            for(i = 0;i < n - 1;i++){
                for(j = 0;j < m;j++){
                    lines[j]+=(v[i][j]+ps[i]+ps2[j])%2;
                }
            }
            if(cnt2 == 0)for(j = 0;j < m;j++)lines[j]++;
            std::sort(lines,lines + m);
            int sum = 0,ans;
            for(i = m-1;i >= 0;i--)sum+=lines[i];
            if(cnt2 == 0)sum-=lines[m - 1];lines[m - 1] = n - lines[m - 1];sum+=lines[m - 1];
            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];
                if(ans > sum)ans = sum;
            }
            printf("%d",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
**/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 527ms
memory: 10412kb

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: 528ms
memory: 10308kb

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: 482ms
memory: 10372kb

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: 514ms
memory: 10384kb

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: 523ms
memory: 10412kb

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: 116ms
memory: 8844kb

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: 32ms
memory: 3500kb

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: 51ms
memory: 2972kb

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: 6ms
memory: 2324kb

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: 2ms
memory: 1920kb

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: 22ms
memory: 3192kb

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: 1512kb

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: 3ms
memory: 6864kb

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: 1ms
memory: 1556kb

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: -100
Wrong Answer
time: 1ms
memory: 1612kb

input:

3 2
2 1
2 1
1 1

output:

3

result:

wrong answer 1st numbers differ - expected: '2', found: '3'