제출 #681706

#제출 시각아이디문제언어결과실행 시간메모리
681706tvladm2009Bomb (IZhO17_bomb)C++14
100 / 100
342 ms110868 KiB
#include <bits/stdc++.h> using ll = long long; int const nmax = 2500; std::string s[5 + nmax]; int dp[5 + nmax], dp_left[5 + nmax][5 + nmax], dp_right[5 + nmax][5 + nmax], dp_up[5 + nmax][5 + nmax], dp_down[5 + nmax][5 + nmax]; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); int n, m; std::cin >> n >> m; for(int i = 1;i <= n; i++) { std::cin >> s[i]; s[i] = "#" + s[i]; } for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) { if(s[i][j] == '1') { dp_left[i][j] = dp_left[i][j - 1] + 1; dp_up[i][j] = dp_up[i - 1][j] + 1; } } for(int i = n; 1 <= i; i--) for(int j = m; 1 <= j; j--) { if(s[i][j] == '1') { dp_right[i][j] = dp_right[i][j + 1] + 1; dp_down[i][j] = dp_down[i + 1][j] + 1; } } for(int i = 1;i <= n; i++) dp[i] = m + 1; int h = n; for(int i = 1;i <= n; i++) for(int j = 1;j <= m; j++) if(s[i][j] == '1') { h = std::min(h, dp_up[i][j] + dp_down[i][j] - 1); dp[1] = std::min(dp[1], dp_left[i][j] + dp_right[i][j] - 1); } for(int j = 1;j <= m; j++) { int cnt = 0, left = 0, right = m + 1; for(int i = 1;i <= n; i++) { if(s[i][j] == '1') { left = std::max(left, j - dp_left[i][j] + 1); right = std::min(right, j + dp_right[i][j] - 1); cnt++; dp[cnt] = std::min(dp[cnt], right - left + 1); } else { cnt = 0; left = 0; right = m + 1; } } } for(int j = 1; j <= m; j++) { int cnt = 0, left = 0, right = m + 1; for(int i = n; 1 <= i; i--) { if(s[i][j] == '1') { left = std::max(left, j - dp_left[i][j] + 1); right = std::min(right, j + dp_right[i][j] - 1); cnt++; dp[cnt] = std::min(dp[cnt], right - left + 1); } else { cnt = 0; left = 0; right = m + 1; } } } int result = 0; for(int i = 1;i <= h; i++) { if(i > 1) dp[i] = std::min(dp[i], dp[i - 1]); result = std::max(result, dp[i] * i); } std::cout << result << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...