Submission #91428

# Submission time Handle Problem Language Result Execution time Memory
91428 2018-12-27T12:45:40 Z Vardanyan Bomb (IZhO17_bomb) C++14
44 / 100
1000 ms 74364 KB
#include<bits/stdc++.h>

using namespace std;
const int N = 2505;
int a[N][N];
int pref[N][N];
int pref2[N][N];
int calc1(int x1,int y1,int x2,int y2){
    return pref[x2][y2]-pref[x2][y1-1]-pref[x1-1][y2]+pref[x1-1][y1-1];
}
int calc2(int x1,int y1,int x2,int y2){
    return pref2[x2][y2]-pref2[x2][y1-1]-pref2[x1-1][y2]+pref2[x1-1][y1-1];
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            char c;
            scanf(" %c",&c);
            a[i][j] = (c == '1');
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            pref[i][j] = pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j];
        }
    }
    int ans = 1;
    for(int p = n;p>=1;p--){
        int lo = 1;
        int hi = m;
        int as = -1;
        while(lo<=hi){
            int mid = (lo+hi)/2;
            int x = p;
            int y = mid;
            bool f = true;
            for(int i = 1;i<=n;i++){
                for(int j = 1;j<=m;j++){
                  //  if(a[i][j]!=1) continue;
                    pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1];
                    if(i+x-1<=n && j+y-1<=m){
                        if(calc1(i,j,i+x-1,j+y-1) == mid*p){
                            pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]+1;
                        }
                    }
                    if(a[i][j] == 0) continue;
                    int x1 = i-x+1;
                    int y1 = j-y+1;
                    x1 = max(1,x1);
                    y1 = max(1,y1);
                    if(calc2(x1,y1,i,j) == 0){
                        f = false;
                        break;
                    }
                }
                if(!f) break;
            }
            if(f){
              //  F = true;
              //  break;
              lo = mid+1;
              as = mid;
              continue;
            }
            swap(x,y);
            f = true;
            for(int i = 1;i<=n;i++){
                for(int j = 1;j<=m;j++){
                 //   if(a[i][j]!=1) continue;
                    pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1];
                    if(i+x-1<=n && j+y-1<=m){
                        if(calc1(i,j,i+x-1,j+y-1) == mid*p){
                            pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]+1;
                        }
                    }
                    if(a[i][j] == 0) continue;
                    int x1 = i-x+1;
                    int y1 = j-y+1;
                    x1 = max(1,x1);
                    y1 = max(1,y1);
                    if(calc2(x1,y1,i,j) == 0){
                        f = false;
                        break;
                    }
                }
                if(!f) break;
            }

            if(f){
             //   F = true;
               // break;
                lo = mid+1;
                as = mid;
                continue;
            }
            hi = mid-1;
            if(hi*p<=ans) break;
        }
        if(as == -1) continue;
        ans = max(ans,as*p);
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
bomb.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&c);
             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 57 ms 30536 KB Output is correct
4 Correct 36 ms 30552 KB Output is correct
5 Correct 2 ms 30552 KB Output is correct
6 Correct 2 ms 30552 KB Output is correct
7 Correct 2 ms 30552 KB Output is correct
8 Correct 2 ms 30552 KB Output is correct
9 Correct 2 ms 30552 KB Output is correct
10 Correct 2 ms 30552 KB Output is correct
11 Correct 2 ms 30552 KB Output is correct
12 Correct 2 ms 30552 KB Output is correct
13 Correct 2 ms 30552 KB Output is correct
14 Correct 2 ms 30552 KB Output is correct
15 Correct 2 ms 30552 KB Output is correct
16 Correct 2 ms 30552 KB Output is correct
17 Correct 3 ms 30552 KB Output is correct
18 Correct 3 ms 30552 KB Output is correct
19 Correct 4 ms 30552 KB Output is correct
20 Correct 4 ms 30552 KB Output is correct
21 Correct 3 ms 30552 KB Output is correct
22 Correct 3 ms 30552 KB Output is correct
23 Correct 5 ms 30552 KB Output is correct
24 Correct 4 ms 30552 KB Output is correct
25 Correct 8 ms 30552 KB Output is correct
26 Correct 6 ms 30552 KB Output is correct
27 Correct 12 ms 30552 KB Output is correct
28 Correct 14 ms 30552 KB Output is correct
29 Correct 128 ms 30552 KB Output is correct
30 Correct 346 ms 30552 KB Output is correct
31 Correct 210 ms 30552 KB Output is correct
32 Correct 188 ms 30552 KB Output is correct
33 Correct 366 ms 30552 KB Output is correct
34 Correct 16 ms 30552 KB Output is correct
35 Correct 113 ms 30552 KB Output is correct
36 Correct 340 ms 30552 KB Output is correct
37 Correct 2 ms 30552 KB Output is correct
38 Execution timed out 1083 ms 74108 KB Time limit exceeded
39 Correct 2 ms 74108 KB Output is correct
40 Execution timed out 1068 ms 74108 KB Time limit exceeded
41 Correct 2 ms 74108 KB Output is correct
42 Correct 9 ms 74108 KB Output is correct
43 Execution timed out 1078 ms 74108 KB Time limit exceeded
44 Correct 635 ms 74108 KB Output is correct
45 Execution timed out 1084 ms 74108 KB Time limit exceeded
46 Correct 676 ms 74168 KB Output is correct
47 Execution timed out 1088 ms 74168 KB Time limit exceeded
48 Execution timed out 1074 ms 74236 KB Time limit exceeded
49 Execution timed out 1073 ms 74236 KB Time limit exceeded
50 Execution timed out 1081 ms 74236 KB Time limit exceeded
51 Execution timed out 1072 ms 74236 KB Time limit exceeded
52 Execution timed out 1068 ms 74236 KB Time limit exceeded
53 Execution timed out 1064 ms 74236 KB Time limit exceeded
54 Execution timed out 1076 ms 74236 KB Time limit exceeded
55 Execution timed out 1079 ms 74236 KB Time limit exceeded
56 Execution timed out 1077 ms 74236 KB Time limit exceeded
57 Execution timed out 1084 ms 74236 KB Time limit exceeded
58 Execution timed out 1084 ms 74236 KB Time limit exceeded
59 Execution timed out 1083 ms 74236 KB Time limit exceeded
60 Execution timed out 1069 ms 74236 KB Time limit exceeded
61 Execution timed out 1088 ms 74236 KB Time limit exceeded
62 Execution timed out 1070 ms 74236 KB Time limit exceeded
63 Execution timed out 1083 ms 74236 KB Time limit exceeded
64 Execution timed out 1084 ms 74236 KB Time limit exceeded
65 Execution timed out 1084 ms 74236 KB Time limit exceeded
66 Execution timed out 1081 ms 74236 KB Time limit exceeded
67 Execution timed out 1078 ms 74236 KB Time limit exceeded
68 Execution timed out 1076 ms 74236 KB Time limit exceeded
69 Execution timed out 1070 ms 74236 KB Time limit exceeded
70 Execution timed out 1072 ms 74236 KB Time limit exceeded
71 Execution timed out 1082 ms 74236 KB Time limit exceeded
72 Execution timed out 1077 ms 74236 KB Time limit exceeded
73 Execution timed out 1075 ms 74236 KB Time limit exceeded
74 Execution timed out 1086 ms 74236 KB Time limit exceeded
75 Execution timed out 1089 ms 74236 KB Time limit exceeded
76 Execution timed out 1077 ms 74236 KB Time limit exceeded
77 Execution timed out 1087 ms 74236 KB Time limit exceeded
78 Execution timed out 1050 ms 74236 KB Time limit exceeded
79 Execution timed out 1063 ms 74236 KB Time limit exceeded
80 Execution timed out 1088 ms 74236 KB Time limit exceeded
81 Execution timed out 1086 ms 74236 KB Time limit exceeded
82 Execution timed out 1085 ms 74236 KB Time limit exceeded
83 Execution timed out 1088 ms 74236 KB Time limit exceeded
84 Correct 594 ms 74236 KB Output is correct
85 Execution timed out 1083 ms 74236 KB Time limit exceeded
86 Execution timed out 1081 ms 74236 KB Time limit exceeded
87 Execution timed out 1084 ms 74236 KB Time limit exceeded
88 Execution timed out 1077 ms 74236 KB Time limit exceeded
89 Execution timed out 1094 ms 74236 KB Time limit exceeded
90 Execution timed out 1086 ms 74236 KB Time limit exceeded
91 Execution timed out 1081 ms 74236 KB Time limit exceeded
92 Execution timed out 1066 ms 74236 KB Time limit exceeded
93 Execution timed out 1086 ms 74236 KB Time limit exceeded
94 Execution timed out 1086 ms 74236 KB Time limit exceeded
95 Execution timed out 1080 ms 74236 KB Time limit exceeded
96 Execution timed out 1078 ms 74236 KB Time limit exceeded
97 Execution timed out 1077 ms 74236 KB Time limit exceeded
98 Execution timed out 1083 ms 74236 KB Time limit exceeded
99 Execution timed out 1077 ms 74236 KB Time limit exceeded
100 Correct 910 ms 74364 KB Output is correct