Submission #423303

#TimeUsernameProblemLanguageResultExecution timeMemory
423303antimirageBomb (IZhO17_bomb)C++14
100 / 100
734 ms74844 KiB
/* * let's for fixed width X find the maximum valid height Y, denote it by ans[X]. * upper bound of Y for every X is ans[1]. * */ #include <iostream> #include <vector> #include <algorithm> #include <assert.h> using namespace std; int main() { int n, m, res = 0; cin >> n >> m; vector <vector <int>> a(n + 5, vector<int>(m + 5, 0)); for (int i = 1; i <= n; i++) { scanf("\n"); for (int j = 1; j <= m; j++) { char ch; scanf("%c", &ch); a[i][j] = ch - 48; } } vector <vector <int>> up(n + 5, vector<int>(m + 5, 0)); vector <vector <int>> dn(n + 5, vector<int>(m + 5, 0)); for (int j = 1; j <= m; j++) { for (int i = 1; i <= n; i++) { up[i][j] = a[i][j] ? up[i - 1][j] + 1 : 0; } for (int i = n; i >= 1; i--) { dn[i][j] = a[i][j] ? dn[i + 1][j] + 1 : 0; } } vector <int> ans(m + 5, n); for (int t = 0; t < 2; t++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j]) ans[1] = min(ans[1], up[i][j] + dn[i][j] - 1); } for (int j = 1; j <= m; j++) { if (a[i][j] && !a[i][j - 1]) { int min_d = n, min_u = n, k; for (k = j; a[i][k]; k++) { min_d = min(min_d, dn[i][k]); min_u = min(min_u, up[i][k]); ans[k - j + 1] = min(ans[k - j + 1], min_d + min_u - 1); } ans[k - j + 1] = 0; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j + j <= m; j++) { swap(a[i][j], a[i][m - j + 1]); swap(up[i][j], up[i][m - j + 1]); swap(dn[i][j], dn[i][m - j + 1]); } } } for (int i = 1; i <= m; i++) { ans[i] = min(ans[i], ans[i - 1]); res = max(res, i * ans[i]); //cout << i << " --> " << ans[i] << endl; } cout << res << endl; }

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("\n");
      |         ~~~~~^~~~~~
bomb.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |             scanf("%c", &ch);
      |             ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...