Submission #1128522

#TimeUsernameProblemLanguageResultExecution timeMemory
1128522erasyl123Bomb (IZhO17_bomb)C++20
0 / 100
2 ms584 KiB
#include <bits/stdc++.h> #define int long long #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const int N = 2505; const int inf = 1e9; const int mod=1e9+7; struct edge{ int pos,val,t; }; int dp[N][N]; string c[N]; int dp1[N][N]; int n,m; vector<pair<int,int> >v[N]; int ch(int mid){ int ok=0; for(int k=0;k<v[mid].size();k++){ int cnt=0; int i=v[mid][k].first; int j=v[mid][k].second; for(int y=1;y+i-1<=n;y++){ for(int x=1;x+j-1<=m;x++){ int x1=x+(j-1); int y1=y+(i-1); int cnt=dp[y1][x1]-dp[y1][x - 1]-dp[y - 1][x1]+dp[y - 1][x - 1]; if(cnt==i*j){ dp1[y][x]++; dp1[y1+1][x]--; dp1[y][x1+1]--; dp1[y1+1][x1+1]++; } } } int cnt1=0; for(int y=1;y<=n;y++){ for(int x=1;x<=m;x++){ dp1[y][x]+=dp1[y-1][x]+dp1[y][x-1]-dp1[y-1][x-1]; if(dp1[y][x]>0){ cnt1++; } } } if(cnt1==dp[n][m]){ ok=1; } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp1[i][j]=0; } } if(ok==1){ break; } } return ok; } signed main(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); boost cin>>n>>m; for(int i=1;i<=n;i++){ cin>>c[i]; for(int j=0;j<m;j++){ int x=0; if(c[i][j]=='1'){ x=1; } dp[i][j+1]=dp[i-1][j+1]+dp[i][j]-dp[i-1][j]+x; } } int mx = m, mx1 = n; for(int i = 1; i <= n; i++) { int cnt = 0; for(int j = 0; j < m; j++) { if(c[i][j] == '1')cnt ++; else if(j > 0 && c[i][j - 1] == '1' && c[i][j] == '0') { mx = min(mx, cnt); cnt = 0; } } if(c[i][m - 1] == '1')mx = min(mx, cnt); } for(int j = 0; j < m; j++) { int cnt = 0; for(int i = 1; i <= n; i++) { if(c[i][j] == '1')cnt ++; else if(j > 0 && c[i - 1][j] == '1' && c[i][j] == '0') { mx1 = min(mx1, cnt); cnt = 0; } } if(c[n][j] == '1')mx1 = min(mx1, cnt); } for(int i=1;i<=2500;i++){ if(i > mx1)break; for(int j=1;j<=i;j++){ if(i%j==0){ if((i / j) > mx)continue; v[i].push_back({j,i/j}); } } } int ans=1; for(int i=2;i<=n*m;i++){ if(ch(i)==1){ ans=i; } } cout<<ans; }

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:59:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bomb.cpp:60:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...