제출 #1129141

#제출 시각아이디문제언어결과실행 시간메모리
1129141GrayBomb (IZhO17_bomb)C++17
34 / 100
503 ms147604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define ff first #define ss second #define ln "\n" #define mp make_pair const ll INF = 2e18; const ll MOD = 1e9+7; void solve(){ ll n, m; cin >> n >> m; vector<vector<ll>> a(n+1, vector<ll>(m+1)); for (ll i=1; i<=n; i++){ for (ll j=1; j<=m; j++){ char x; cin >> x; a[i][j]=x-'0'; } } vector<vector<ll>> wl(n+1, vector<ll>(m+1)), wr(n+1, vector<ll>(m+1)); for (ll i=1; i<=n; i++){ for (ll j=1; j<=m; j++){ if (a[i][j]) wl[i][j]=wl[i][j-1]+1; } for (ll j=m; j>=1; j--){ if (a[i][j]) wr[i][j]=1; if (j+1<=m) wr[i][j]+=wr[i][j+1]; } } vector<ll> h(n+1, INF), ah(n+1); for (ll j=1; j<=m; j++){ ll exist=0; for (ll i=1; i<=n; i++){ if (a[i][j]) exist=1; } if (!exist) continue; ll l=INF, r=INF, hcnt=0; ah.assign(n+1, INF); for (ll i=1; i<=n; i++){ if (a[i][j]){ l=min(l, wl[i][j]); r=min(r, wr[i][j]); hcnt++; ah[hcnt]=min(ah[hcnt], l+r-1); // cout << i << "-" << j << ": " << hcnt << "-" << l+r-1 << ln; }else{ l=INF; r=INF; hcnt=0; } } l=INF; r=INF; hcnt=0; for (ll i=n; i>=1; i--){ if (a[i][j]){ l=min(l, wl[i][j]); r=min(r, wr[i][j]); hcnt++; ah[hcnt]=min(ah[hcnt], l+r-1); }else{ l=INF; r=INF; hcnt=0; } } for (ll i=1; i<=n; i++){ h[i]=min(h[i], (ah[i]==INF?0:ah[i])); } } ll res=0; for (ll i=1; i<=n; i++){ if (h[i]==INF) continue; res=max(res, i*h[i]); } cout << res << ln; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); auto start = chrono::high_resolution_clock::now(); ll t=1; // cin >> t; while (t--) solve(); #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...