Submission #91270

#TimeUsernameProblemLanguageResultExecution timeMemory
91270VardanyanBomb (IZhO17_bomb)C++14
7 / 100
110 ms8416 KiB
#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); if(n>450 || m>450) return 0; 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<=n;j++){ pref[i][j] = pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j]; } } int l = 1; int r = n*m; int ans = 1; while(l<=r){ int mid = (l+r)/2; bool F = false; for(int q = 1;q<=sqrt(mid);q++){ if(mid%q) continue; int x = mid/q; int y = q; bool f = true; for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) pref2[i][j] = 0; 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){ 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){ F = true; break; } swap(x,y); f = true; for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) pref2[i][j] = 0; for(int i = 1;i<=n;i++){ for(int j = 1;j<=m;j++){ if(a[i][j]!=1) continue; if(i+x-1<=n && j+y-1<=m){ if(calc1(i,j,i+x-1,j+y-1) == mid){ pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]+1; } else{ pref2[i][j] = pref2[i-1][j]+pref2[i][j-1]-pref2[i-1][j-1]; } } 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){ F = true; break; } } if(F){ ans = mid; l = mid+1; } else r = mid-1; } cout<<ans<<endl; return 0; }

Compilation message (stderr)

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:22:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c",&c);
             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...