Submission #333927

# Submission time Handle Problem Language Result Execution time Memory
333927 2020-12-08T03:28:43 Z juggernaut Bomb (IZhO17_bomb) C++14
34 / 100
1000 ms 55680 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,mx,cnt[2505][2505],pref[2505][2505];
bool a[2505][2505];
char rd(){
    char ch;
    do{
        scanf("%c",&ch);
    }while(ch!='0'&&ch!='1');
    return ch;
}
bool sum(int x,int y,int x2,int y2){
    return (cnt[x2][y2]-cnt[x2][y-1]-cnt[x-1][y2]+cnt[x-1][y-1])==((x2-x+1)*(y2-y+1));
}
bool check(int x,int y){
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)pref[i][j]=0;
    for(int i=1;i+x-1<=n;i++)
        for(int j=1;j+y-1<=m;j++)
            if(sum(i,j,i+x-1,j+y-1)){
                for(int k=i;k<=i+x-1;k++)pref[k][j]++,pref[k][j+y]--;
            }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            pref[i][j]+=pref[i][j-1];
            if(a[i][j]&&!pref[i][j])return false;
        }
    }
    return true;
}
bool check_1(int x,int y){
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)pref[i][j]=0;
    for(int i=1;i+x-1<=n;i++)
        for(int j=1;j+y-1<=m;j++)
            if(sum(i,j,i+x-1,j+y-1)){
                for(int k=j;k<=j+y-1;k++)pref[i][k]++,pref[i+x][k]--;
            }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            pref[i][j]+=pref[i-1][j];
            if(a[i][j]&&!pref[i][j])return false;
        }
    }
    return true;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            a[i][j]=(rd()=='1');
            cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+a[i][j];
        }
    if(n<m){
        for(int x=1;x<=n;x++){
            int l=1,r=m;
            while(l<r){
                int mid=(l+r+1)>>1;
                if(check(x,mid))l=mid;
                else r=mid-1;
            }
            if(!check(x,l))l=0;
            mx=max(mx,x*l);
        }
        printf("%d",mx);
    }else{
        for(int x=1;x<=m;x++){
            int l=1,r=n;
            while(l<r){
                int mid=(l+r+1)>>1;
                if(check_1(mid,x))l=mid;
                else r=mid-1;
            }
            if(!check_1(l,x))l=0;
            mx=max(mx,x*l);
        }
        printf("%d",mx);
    }
}

Compilation message

bomb.cpp: In function 'char rd()':
bomb.cpp:8:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |         scanf("%c",&ch);
      |         ~~~~~^~~~~~~~~~
bomb.cpp: In function 'int main()':
bomb.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 18 ms 26476 KB Output is correct
4 Correct 17 ms 26476 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 4 ms 1004 KB Output is correct
18 Correct 4 ms 1132 KB Output is correct
19 Correct 9 ms 1388 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 5 ms 1004 KB Output is correct
22 Correct 7 ms 1132 KB Output is correct
23 Correct 15 ms 1516 KB Output is correct
24 Correct 7 ms 1260 KB Output is correct
25 Correct 19 ms 1516 KB Output is correct
26 Correct 94 ms 1516 KB Output is correct
27 Execution timed out 1098 ms 4076 KB Time limit exceeded
28 Correct 356 ms 4332 KB Output is correct
29 Execution timed out 1091 ms 5356 KB Time limit exceeded
30 Execution timed out 1037 ms 6252 KB Time limit exceeded
31 Correct 857 ms 5100 KB Output is correct
32 Correct 833 ms 5876 KB Output is correct
33 Execution timed out 1055 ms 6636 KB Time limit exceeded
34 Correct 241 ms 4844 KB Output is correct
35 Execution timed out 1095 ms 6636 KB Time limit exceeded
36 Execution timed out 1089 ms 6636 KB Time limit exceeded
37 Correct 1 ms 512 KB Output is correct
38 Execution timed out 1093 ms 55532 KB Time limit exceeded
39 Correct 1 ms 492 KB Output is correct
40 Execution timed out 1095 ms 15596 KB Time limit exceeded
41 Correct 1 ms 492 KB Output is correct
42 Correct 47 ms 1516 KB Output is correct
43 Execution timed out 1089 ms 55532 KB Time limit exceeded
44 Execution timed out 1088 ms 6636 KB Time limit exceeded
45 Execution timed out 1055 ms 55532 KB Time limit exceeded
46 Execution timed out 1060 ms 55532 KB Time limit exceeded
47 Execution timed out 1093 ms 55532 KB Time limit exceeded
48 Execution timed out 1070 ms 55616 KB Time limit exceeded
49 Execution timed out 1069 ms 55680 KB Time limit exceeded
50 Execution timed out 1063 ms 55444 KB Time limit exceeded
51 Execution timed out 1047 ms 55660 KB Time limit exceeded
52 Execution timed out 1054 ms 55532 KB Time limit exceeded
53 Execution timed out 1054 ms 55516 KB Time limit exceeded
54 Execution timed out 1069 ms 55532 KB Time limit exceeded
55 Execution timed out 1051 ms 55516 KB Time limit exceeded
56 Execution timed out 1089 ms 55624 KB Time limit exceeded
57 Execution timed out 1098 ms 55532 KB Time limit exceeded
58 Execution timed out 1094 ms 55404 KB Time limit exceeded
59 Execution timed out 1097 ms 55532 KB Time limit exceeded
60 Execution timed out 1089 ms 55532 KB Time limit exceeded
61 Execution timed out 1095 ms 55532 KB Time limit exceeded
62 Execution timed out 1083 ms 55532 KB Time limit exceeded
63 Execution timed out 1092 ms 55532 KB Time limit exceeded
64 Execution timed out 1095 ms 55532 KB Time limit exceeded
65 Execution timed out 1094 ms 55532 KB Time limit exceeded
66 Execution timed out 1101 ms 55532 KB Time limit exceeded
67 Execution timed out 1098 ms 55532 KB Time limit exceeded
68 Execution timed out 1035 ms 55532 KB Time limit exceeded
69 Execution timed out 1085 ms 55532 KB Time limit exceeded
70 Execution timed out 1070 ms 44524 KB Time limit exceeded
71 Execution timed out 1095 ms 55404 KB Time limit exceeded
72 Execution timed out 1091 ms 55532 KB Time limit exceeded
73 Execution timed out 1093 ms 55532 KB Time limit exceeded
74 Execution timed out 1092 ms 55532 KB Time limit exceeded
75 Execution timed out 1062 ms 55404 KB Time limit exceeded
76 Execution timed out 1073 ms 55404 KB Time limit exceeded
77 Execution timed out 1052 ms 55532 KB Time limit exceeded
78 Execution timed out 1056 ms 55532 KB Time limit exceeded
79 Execution timed out 1068 ms 55532 KB Time limit exceeded
80 Execution timed out 1056 ms 55532 KB Time limit exceeded
81 Execution timed out 1061 ms 55532 KB Time limit exceeded
82 Execution timed out 1087 ms 55532 KB Time limit exceeded
83 Execution timed out 1055 ms 55532 KB Time limit exceeded
84 Execution timed out 1085 ms 55660 KB Time limit exceeded
85 Execution timed out 1058 ms 55660 KB Time limit exceeded
86 Execution timed out 1095 ms 55532 KB Time limit exceeded
87 Execution timed out 1084 ms 55600 KB Time limit exceeded
88 Execution timed out 1094 ms 55404 KB Time limit exceeded
89 Execution timed out 1098 ms 55660 KB Time limit exceeded
90 Execution timed out 1087 ms 44652 KB Time limit exceeded
91 Execution timed out 1059 ms 55532 KB Time limit exceeded
92 Execution timed out 1096 ms 55416 KB Time limit exceeded
93 Execution timed out 1099 ms 55532 KB Time limit exceeded
94 Execution timed out 1089 ms 55532 KB Time limit exceeded
95 Execution timed out 1099 ms 55532 KB Time limit exceeded
96 Execution timed out 1087 ms 55404 KB Time limit exceeded
97 Execution timed out 1052 ms 55532 KB Time limit exceeded
98 Execution timed out 1063 ms 55660 KB Time limit exceeded
99 Execution timed out 1094 ms 55532 KB Time limit exceeded
100 Execution timed out 1086 ms 55532 KB Time limit exceeded