Submission #1128734

#TimeUsernameProblemLanguageResultExecution timeMemory
1128734_TemirhanBomb (IZhO17_bomb)C++20
20 / 100
1102 ms124628 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define sz(x) x.size() #define F first #define S second #define nl '\n' void Tima() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int N = 3000; const int inf = 1e12; const int mod = 1e9 + 7; int n, m, p[N][N], p1[N][N]; string t[N]; bool ch( int x, int y ) { for( int i = 1; i + x - 1 <= n; ++i ) for( int j = 1; j + y - 1 <= m; ++j ) if( p[i + x - 1][j + y - 1] - p[i + x - 1][j - 1] - p[i - 1][j + y - 1] + p[i - 1][j - 1] == x * y ) { ++p1[i][j]; --p1[i + x][j]; --p1[i][j + y]; ++p1[i + x][j + y]; } bool ch = true; for( int i = 1; i <= n; ++i ) for( int j = 1; j <= m; ++j ) { p1[i][j] += p1[i - 1][j] + p1[i][j - 1] - p1[i - 1][j - 1]; if( !p1[i][j] && t[i - 1][j - 1] == '1' ) ch = false; } for( int i = 1; i <= n + 1; ++i ) for( int j = 1; j <= m + 1; ++j ) p1[i][j] = 0; return ch; } signed main() { // Tima(); ios_base::sync_with_stdio(0); cin.tie(0); cin >>n >>m; for( int i = 0; i < n; ++i ) { cin >>t[i]; for( int j = 0; j < m; ++j ) if( t[i][j] == '1' ) ++p[i + 1][j + 1]; } for( int i = 1; i <= n; ++i ) for( int j = 1; j <= m; ++j ) p[i][j] += p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1]; int l = 1, r = n, mid; while( l + 1 < r ) { mid = (l + r) / 2; if( ch(mid, 1) ) l = mid; else r = mid; } int len = l; if( ch(r, 1) ) len = r; l = 1; r = m; while( l + 1 < r ) { mid = (l + r) / 2; if( ch(len, mid) ) l = mid; else r = mid; } if( ch(len, r) ) l = r; int ans = len * l; l = 1; r = m; while( l + 1 < r ) { mid = (l + r) / 2; if( ch(1, mid) ) l = mid; else r = mid; } if( ch(1, r) ) l = r; len = l; l = 1; r = n; while( l + 1 < r ) { mid = (l + r) / 2; if( ch(mid, len) ) l = mid; else r = mid; } if( ch(r, len) ) l = r; ans = max(ans, l * len); cout <<ans; }

Compilation message (stderr)

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