# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96765 | choikiwon | Bomb (IZhO17_bomb) | C++17 | 921 ms | 107896 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
int mn[MN];
int main() {
//freopen("input.txt", "r", stdin);
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));
int mnh = 1e9;
int mnw = 1e9;
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) if(G[i][j] == '1') {
mnh = min(mnh, dp(i, j, 0) + dp(i, j, 1) - 1);
mnw = min(mnw, dp(i, j, 2) + dp(i, j, 3) - 1);
}
for(int i = 0; i <= mnw; i++) mn[i] = 1e9;
mn[0] = mnh;
for(int i = 0; i < N; i++) {
int len = 0;
int chk1 = 0, chk2 = 0;
for(int j = 0; j < M; j++) {
if(G[i][j] == '1') {
if(dp(i, j, 3) == 1) {
len = 1;
}
if(len) {
if(dp(i, j, 0) == 1) chk1 = 1;
if(chk1) mn[len] = min(mn[len], dp(i, j, 1));
if(dp(i, j, 1) == 1) chk2 = 1;
if(chk2) mn[len] = min(mn[len], dp(i, j, 0));
}
len++;
}
else len = 0, chk1 = 0, chk2 = 0;
}
len = 0;
chk1 = 0, chk2 = 0;
for(int j = M - 1; j >= 0; j--) {
if(G[i][j] == '1') {
if(dp(i, j, 2) == 1) {
len = 1;
}
if(len) {
if(dp(i, j, 0) == 1) chk1 = 1;
if(chk1) mn[len] = min(mn[len], dp(i, j, 1));
if(dp(i, j, 1) == 1) chk2 = 1;
if(chk2) mn[len] = min(mn[len], dp(i, j, 0));
}
len++;
}
else len = 0, chk1 = 0, chk2 = 0;
}
}
/*
for(int i = 0; i < N; i++) {
int tmn = 1e9;
int len = 0;
for(int j = 0; j < M; j++) {
if(G[i][j] == '1') {
if(len) tmn = min(tmn, dp(i, j, 1));
if(dp(i, j, 0) == 1) {
if(len) mn[len - 1] = min(mn[len - 1], tmn);
tmn = dp(i, j, 1);
len = 1;
}
if(len) len++;
}
else tmn = 1e9, len = 0;
}
tmn = 1e9;
len = 0;
for(int j = 0; j < M; j++) {
if(G[i][j] == '1') {
if(len) tmn = min(tmn, dp(i, j, 0));
if(dp(i, j, 1) == 1) {
if(len) mn[len - 1] = min(mn[len - 1], tmn);
tmn = dp(i, j, 0);
len = 1;
}
if(len) len++;
}
else tmn = 1e9, len = 0;
}
}
//*/
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |