Submission #165639

#TimeUsernameProblemLanguageResultExecution timeMemory
165639qkxwsmBomb (IZhO17_bomb)C++14
100 / 100
410 ms56568 KiB
#include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) ((x).size())) #define ALL(x) (x).begin(), (x).end() #define MAXN 2513 #define INF 1000000007 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; int N, M; bitset<MAXN> grid[MAXN]; int up[MAXN][MAXN], dn[MAXN][MAXN]; int dp[MAXN]; int ans; int width = INF; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(12); cerr << fixed << setprecision(4); cin >> N >> M; FOR(i, 0, N) { string temps; cin >> temps; FOR(j, 0, M) { grid[i][j] = (temps[j] == '1'); } } //length of shortest vertical strip. FOR(i, 0, M + 1) { dp[i] = INF; } // cerr << dp[2] << endl; FOR(i, 0, M) { int sum = 0; FOR(j, 0, N) { if (grid[j][i]) sum++; else { if (sum) ckmin(dp[1], sum); sum = 0; } } if (sum) ckmin(dp[1], sum); } FOR(i, 0, N) { int sum = 0; FOR(j, 0, M) { if (grid[i][j]) sum++; else { if (sum) ckmin(width, sum); sum = 0; } } if (sum) ckmin(width, sum); } if (width >= INF) { cout << N * M << '\n'; return 0; } // cerr << dp[1] << endl; FOR(j, 0, M) { FOR(i, 0, N) { if (!grid[i][j]) up[i][j] = i + 1; else up[i][j] = (i == 0 ? 0 : up[i - 1][j]); } FORD(i, N, 0) { if (!grid[i][j]) dn[i][j] = i - 1; else dn[i][j] = (i == N - 1 ? N - 1 : dn[i + 1][j]); } } // FOR(i, 0, N) // { // FOR(j, 0, M) // { // cerr << up[i][j] << ' '; // } // cerr << endl; // } // FOR(i, 0, N) // { // FOR(j, 0, M) // { // cerr << dn[i][j] << ' '; // } // cerr << endl; // } FOR(i, 0, N) { int sum = 0; pii bound = {0, N - 1}; FOR(j, 0, M) { if (grid[i][j]) { sum++; ckmin(bound.se, dn[i][j]); ckmax(bound.fi, up[i][j]); } else { sum = 0; bound = {0, N - 1}; } if (sum > 1) ckmin(dp[sum], bound.se - bound.fi + 1); // cerr << sum << ',' << bound.se << ' ' << bound.fi << ' ' << bound.se - bound.fi + 1 << ' '; } // cerr << endl; } FOR(i, 0, N) { int sum = 0; pii bound = {0, N - 1}; FORD(j, M, 0) { if (grid[i][j]) { sum++; ckmin(bound.se, dn[i][j]); ckmax(bound.fi, up[i][j]); } else { sum = 0; bound = {0, N - 1}; } if (sum > 1) ckmin(dp[sum], bound.se - bound.fi + 1); // cerr << sum << ',' << bound.se - bound.fi + 1 << ' '; } // cerr << endl; } FOR(i, 1, width + 1) { ckmin(dp[i], dp[1]); ckmax(ans, dp[i] * i); // cerr << dp[i] << endl; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...