# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
180297 | srvlt | Bomb (IZhO17_bomb) | C++14 | 748 ms | 123740 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"
//#define int long long
using namespace std;
void dout() {
cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 2503, inf = 1e4;
int n, m, a[N][N], top[N][N], bot[N][N];
int h[N], W = inf, H = inf, row[N][N], col[N][N];
void solve(int tc) {
// check for (int i = 0; i < n; j++)
cin >> n >> m;
char c;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c;
if (c == '1') {
a[i][j] = 1;
}
}
}
for (int i = 1; i <= m; i++) {
bot[n + 1][i] = n + 1;
}
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
top[i][j] = top[i - 1][j];
if (!a[i][j]) {
top[i][j] = i;
}
}
for (int i = n; i >= 1; i--) {
bot[i][j] = bot[i + 1][j];
if (!a[i][j]) {
bot[i][j] = i;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j]) {
row[i][j] = row[i][j - 1] + 1;
} else {
if (row[i][j - 1] > 0) {
W = min(W, row[i][j - 1]);
}
}
}
if (row[i][m] > 0) {
W = min(W, row[i][m]);
}
}
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
if (a[i][j]) {
col[i][j] = col[i - 1][j] + 1;
} else {
if (col[i - 1][j] > 0) {
H = min(H, col[i - 1][j]);
}
}
}
if (col[n][j] > 0) {
H = min(H, col[n][j]);
}
}
for (int i = 1; i <= m; i++) {
h[i] = H;
}
for (int i = 1; i <= n; i++) {
int last = -1, mn = inf, mx = -inf;
for (int j = 1; j <= m; j++) {
if (!a[i][j]) {
last = -1;
mn = inf, mx = -inf;
} else {
if (last == -1) {
last = j;
}
mn = min(mn, bot[i][j]);
mx = max(mx, top[i][j]);
h[j - last + 1] = min(h[j - last + 1], mn - mx - 1);
}
}
last = -1, mn = inf, mx = -inf;
for (int j = m; j >= 1; j--) {
if (!a[i][j]) {
last = -1;
mn = inf, mx = -inf;
} else {
if (last == -1) {
last = j;
}
mn = min(mn, bot[i][j]);
mx = max(mx, top[i][j]);
h[last - j + 1] = min(h[last - j + 1], mn - mx - 1);
}
}
}
int mn = inf, mx = 0;
for (int i = 1; i <= W; i++) {
mn = h[i];
mx = max(mx, mn * i);
}
cout << mx;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int i = 0; i < tc; i++) {
solve(i);
// cleanup();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |