Submission #96447

#TimeUsernameProblemLanguageResultExecution timeMemory
96447choikiwonBomb (IZhO17_bomb)C++17
37 / 100
1045 ms108224 KiB
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int MN = 2525; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int N, M; char G[MN][MN]; int cc[MN][MN][4]; int dp(int r, int c, int d) { if(r < 0 || N <= r || c < 0 || M <= c) return 0; int &ret = cc[r][c][d]; if(ret != -1) return ret; if(G[r][c] == '0') return ret = 0; return ret = dp(r + dy[d], c + dx[d], d) + 1; } vector<int> V[MN]; int mn[MN]; int main() { scanf("%d %d", &N, &M); for(int i = 0; i < N; i++) { scanf("\n"); for(int j = 0; j < M; j++) { scanf("%c", &G[i][j]); } } memset(cc, -1, sizeof(cc)); for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { if(G[i][j] == '1' && dp(i, j, 0) == 1) { V[i].push_back(j); } } } int mnw = 1e9; for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) if(G[i][j] == '1') { mnw = min(mnw, dp(i, j, 2) + dp(i, j, 3) - 1); } for(int i = 0; i <= mnw; i++) mn[i] = 1e9; for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) if(G[i][j] == '1') { int a = lower_bound(V[i].begin(), V[i].end(), j) - V[i].begin(); int b = a - 1; int l = j - dp(i, j, 3) + 1; int r = j + dp(i, j, 2) - 1; if(a != V[i].size() && V[i][a] <= r) { mn[ V[i][a] - j + 1 ] = min(mn[ V[i][a] - j + 1 ], dp(i, j, 1)); } if(b != -1 && l <= V[i][b]) { mn[ j - V[i][b] + 1 ] = min(mn[ j - V[i][b] + 1 ], dp(i, j, 1)); } } int ans = 0; for(int i = 1; i <= mnw; i++) { mn[i] = min(mn[i], mn[i - 1]); ans = max(ans, mn[i] * i); } printf("%d", ans); }

Compilation message (stderr)

bomb.cpp: In function 'int main()':
bomb.cpp:58:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(a != V[i].size() && V[i][a] <= r) {
            ~~^~~~~~~~~~~~~~
bomb.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
bomb.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n");
         ~~~~~^~~~~~
bomb.cpp:32:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%c", &G[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...