Submission #831260

# Submission time Handle Problem Language Result Execution time Memory
831260 2023-08-20T03:05:39 Z vjudge1 Bomb (IZhO17_bomb) C++17
32 / 100
277 ms 56000 KB
// 赤コーダーになりたい
// お願い いいですか?

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// Pragmas
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

// Namespaces
using namespace std;
using namespace __gnu_pbds;

// Data types
using si	= short int;
using ll	= long long;
using lll	= __int128;
using ld	= long double;

// Pairs
using pii	= pair<int, int>;
using psi	= pair<si, si>;
using pll	= pair<ll, ll>;
using plll	= pair<lll, lll>;
using pld	= pair<ld, ld>;
#define fi	first
#define se	second

// For
#define Frue(i, n, N)		for (int i = (n); i <= (N); i++)
#define  Fru(i, n, N)		for (int i = (n); i <  (N); i++)
#define Frde(i, n, N)		for (int i = (n); i >= (N); i--)
#define  Frd(i, n, N)		for (int i = (n); i >  (N); i--)

// PBDS
template<typename Z>
using ordered_set	= tree<Z, null_type, less<Z>, rb_tree_tag, tree_order_statistics_node_update>;

// Various outputs
template<typename Y, typename Z> ostream& operator<<(ostream &os, const pair<Y, Z> &p) {
	return os << '(' << p.fi << ',' << p.se << ')';
}
template<typename Z> ostream& operator<<(ostream &os, const vector<Z> &v) {
	os << '{'; bool _first = 1;
	for (auto &i : v) {if (!_first) os << ", "; os << i; _first = 0;}
	return os << '}';
}
template<typename Z, unsigned long long sz> ostream& operator<<(ostream &os, const array<Z, sz> &arr) {
	os << '{'; bool _first = 1;
	for (auto &i : arr) {if (!_first) os << ", "; os << i; _first = 0;}
	return os << '}';
}

// Quick macro functions
#define sqr(x)			((x)*(x))
#define debug(x)		cout << #x << " = " << (x) << '\n'
#define debugV(v, x)	cout << #v << "[" << (x) << "] = " << (v[x]) << '\n'
#define rrebug(x)		cerr << #x << " = " << (x) << '\n'
#define rrebugV(v, x)	cerr << #v << "[" << (x) << "] = " << (v[x]) << '\n'

#define All(x)			x.begin(), x.end()
#define Sort(x)			sort(All(x))
#define Reverse(x)		reverse(All(x))
#define Uniqueify(x)	Sort(x); x.erase(unique(All(x)), x.end())

#define RandomSeed			chrono::steady_clock::now().time_since_epoch().count()
#define MultipleTestcases	int _tc; cin >> _tc; for (int _cur_tc = 1; _cur_tc <= _tc; _cur_tc++)

// Check min and max
template<typename Z> void chmin(Z &a, Z b) {a = min(a, b);}
template<typename Z> void chmax(Z &a, Z b) {a = max(a, b);}
 
// Modular arithmetic
template<int MOD>
class ModInt {
  public:
	int v;
	ModInt() : v(0) {}
	ModInt(long long _v) {
		v = int((-MOD < _v && _v < MOD) ? (_v) : (_v % MOD));
		if (v < 0) v += MOD;
	}
 
	friend bool operator==(const ModInt &a, const ModInt &b) {return a.v == b.v;}
	friend bool operator!=(const ModInt &a, const ModInt &b) {return a.v != b.v;}
	friend bool operator< (const ModInt &a, const ModInt &b) {return a.v <  b.v;}
	friend bool operator<=(const ModInt &a, const ModInt &b) {return a.v <= b.v;}
	friend bool operator> (const ModInt &a, const ModInt &b) {return a.v >  b.v;}
	friend bool operator>=(const ModInt &a, const ModInt &b) {return a.v >= b.v;}
 
	ModInt &operator+=(const ModInt &a) {if ((v += a.v) >= MOD) v -= MOD; return *this;}
	ModInt &operator-=(const ModInt &a) {if ((v -= a.v) < 0) v += MOD; return *this;}
	ModInt &operator*=(const ModInt &a) {v = 1ll * v * a.v % MOD; return *this;}
	ModInt &operator/=(const ModInt &a) {return (*this) *= inverse(a);}
 
	friend ModInt pow(ModInt a, long long x) {
		ModInt res = 1;
		for (; x; x /= 2, a *= a) if (x & 1) res *= a;
		return res;
	}
	friend ModInt inverse(ModInt a) {return pow(a, MOD - 2);}
 
	ModInt operator+ () const {return ModInt( v);}
	ModInt operator- () const {return ModInt(-v);}
	ModInt operator++() const {return *this += 1;}
	ModInt operator--() const {return *this -= 1;}
 
	friend ModInt operator+(ModInt a, const ModInt &b) {return a += b;}
	friend ModInt operator-(ModInt a, const ModInt &b) {return a -= b;}
	friend ModInt operator*(ModInt a, const ModInt &b) {return a *= b;}
	friend ModInt operator/(ModInt a, const ModInt &b) {return a /= b;}
 
	friend istream &operator>>(istream &is, ModInt &v) {return is >> v.v;}
	friend ostream &operator<<(ostream &os, const ModInt &v) {return os << v.v;}
};
const int ModA	= 998244353;
const int ModC	= 1e9 + 7;
using MintA	= ModInt<ModA>;
using MintC	= ModInt<ModC>;

// Other constants
const ll INF	= 1e18;
const ll iINF	= 1e9;
const ld EPS	= 1e-9;
const ld iEPS	= 1e-6;

const int maxN	= 2523;

int N, M;
char grid[maxN][maxN];
int up[maxN][maxN], dn[maxN][maxN], minH[maxN];
int boundH = iINF, boundW = iINF, ans = 0;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			cin >> grid[i][j];
		}
	}

	// Precompute up, dn, and boundH
	for (int j = 1; j <= M; j++) {
		for (int i = 1; i <= N; i++) {
			if (grid[i][j] == '0') {
				up[i][j] = 0;
			} else {
				up[i][j] = up[i-1][j] + 1;
				if ((i == N) || (grid[i+1][j] == '0')) {
					boundH = min(boundH, up[i][j]);
				}
			}
		}

		for (int i = N; i >= 1; i--) {
			if (grid[i][j] == '0') {
				dn[i][j] = 0;
			} else {
				dn[i][j] = dn[i+1][j] + 1;
			}
		}
	}

	// Precompute boundW
	for (int i = 1; i <= N; i++) {
		int span = 0;
		for (int j = 1; j <= M; j++) {
			if (grid[i][j] == '0') {
				span = 0;
			} else {
				span += 1;
				if ((j == M) || (grid[i][j+1] == '0')) {
					boundW = min(boundW, span);
				}
			}
		}
	}

	// Compute minH for each horizontal prefix and suffix
	for (int j = 1; j <= M; j++) {
		minH[j] = iINF;
	}
	for (int i = 1; i <= N; i++) {
		int span = 0, mnUp = iINF, mnDn = iINF;
		for (int j = 1; j <= M; j++) {
			if (grid[i][j] == '0') {
				span = 0, mnUp = iINF, mnDn = iINF;
			} else {
				span += 1;
				mnUp = min(mnUp, up[i][j]);
				mnDn = min(mnDn, dn[i][j]);

				minH[span] = min(minH[span], mnUp + mnDn - 1);
			}
		}
		
		span = 0, mnUp = iINF, mnDn = iINF;
		for (int j = M; j >= 1; j--) {
			if (grid[i][j] == '0') {
				span = 0, mnUp = iINF, mnDn = iINF;
			} else {
				span += 1;
				mnUp = min(mnUp, up[i][j]);
				mnDn = min(mnDn, dn[i][j]);

				minH[span] = min(minH[span], mnUp + mnDn - 1);
			}
		}
	}

	for (int j = 1; j <= M; j++) {
		if (minH[j] == iINF) continue;
		ans = max(ans, minH[j] * j);
	}
	ans = min(ans, boundH * boundW);

	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 9 ms 26580 KB Output is correct
4 Correct 9 ms 26580 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Incorrect 0 ms 468 KB Output isn't correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Incorrect 0 ms 468 KB Output isn't correct
11 Incorrect 0 ms 468 KB Output isn't correct
12 Incorrect 0 ms 468 KB Output isn't correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Incorrect 0 ms 468 KB Output isn't correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Output isn't correct
19 Incorrect 1 ms 1364 KB Output isn't correct
20 Incorrect 1 ms 1236 KB Output isn't correct
21 Incorrect 0 ms 852 KB Output isn't correct
22 Correct 1 ms 1108 KB Output is correct
23 Incorrect 1 ms 1364 KB Output isn't correct
24 Incorrect 1 ms 1108 KB Output isn't correct
25 Incorrect 1 ms 1364 KB Output isn't correct
26 Correct 1 ms 1364 KB Output is correct
27 Correct 3 ms 3924 KB Output is correct
28 Correct 3 ms 4180 KB Output is correct
29 Incorrect 4 ms 5332 KB Output isn't correct
30 Incorrect 5 ms 6228 KB Output isn't correct
31 Incorrect 4 ms 4948 KB Output isn't correct
32 Incorrect 5 ms 5716 KB Output isn't correct
33 Incorrect 5 ms 6612 KB Output isn't correct
34 Correct 3 ms 4692 KB Output is correct
35 Incorrect 5 ms 6644 KB Output isn't correct
36 Correct 6 ms 6612 KB Output is correct
37 Incorrect 0 ms 468 KB Output isn't correct
38 Correct 240 ms 55920 KB Output is correct
39 Incorrect 1 ms 468 KB Output isn't correct
40 Incorrect 33 ms 15468 KB Output isn't correct
41 Correct 0 ms 468 KB Output is correct
42 Correct 1 ms 1364 KB Output is correct
43 Correct 232 ms 55816 KB Output is correct
44 Correct 6 ms 6612 KB Output is correct
45 Correct 241 ms 56000 KB Output is correct
46 Correct 229 ms 55820 KB Output is correct
47 Correct 231 ms 55820 KB Output is correct
48 Incorrect 235 ms 55984 KB Output isn't correct
49 Correct 234 ms 55864 KB Output is correct
50 Incorrect 234 ms 55856 KB Output isn't correct
51 Incorrect 243 ms 55992 KB Output isn't correct
52 Incorrect 234 ms 55792 KB Output isn't correct
53 Incorrect 232 ms 55756 KB Output isn't correct
54 Incorrect 229 ms 55960 KB Output isn't correct
55 Incorrect 227 ms 55852 KB Output isn't correct
56 Correct 233 ms 55864 KB Output is correct
57 Incorrect 229 ms 55872 KB Output isn't correct
58 Incorrect 241 ms 55792 KB Output isn't correct
59 Incorrect 227 ms 55836 KB Output isn't correct
60 Correct 238 ms 55860 KB Output is correct
61 Correct 247 ms 55756 KB Output is correct
62 Correct 243 ms 55868 KB Output is correct
63 Correct 239 ms 55872 KB Output is correct
64 Correct 233 ms 55780 KB Output is correct
65 Incorrect 245 ms 55864 KB Output isn't correct
66 Incorrect 233 ms 55832 KB Output isn't correct
67 Incorrect 235 ms 55864 KB Output isn't correct
68 Incorrect 241 ms 55872 KB Output isn't correct
69 Incorrect 225 ms 55756 KB Output isn't correct
70 Incorrect 154 ms 44704 KB Output isn't correct
71 Incorrect 224 ms 55760 KB Output isn't correct
72 Incorrect 230 ms 55852 KB Output isn't correct
73 Incorrect 226 ms 55856 KB Output isn't correct
74 Incorrect 231 ms 55872 KB Output isn't correct
75 Incorrect 241 ms 55868 KB Output isn't correct
76 Incorrect 243 ms 55780 KB Output isn't correct
77 Incorrect 277 ms 55756 KB Output isn't correct
78 Incorrect 234 ms 55868 KB Output isn't correct
79 Incorrect 225 ms 55752 KB Output isn't correct
80 Incorrect 228 ms 55792 KB Output isn't correct
81 Incorrect 221 ms 55864 KB Output isn't correct
82 Incorrect 228 ms 55796 KB Output isn't correct
83 Incorrect 231 ms 55756 KB Output isn't correct
84 Incorrect 231 ms 55916 KB Output isn't correct
85 Incorrect 226 ms 55792 KB Output isn't correct
86 Incorrect 240 ms 55844 KB Output isn't correct
87 Incorrect 226 ms 55884 KB Output isn't correct
88 Incorrect 268 ms 55868 KB Output isn't correct
89 Incorrect 230 ms 55796 KB Output isn't correct
90 Incorrect 158 ms 44836 KB Output isn't correct
91 Incorrect 230 ms 55756 KB Output isn't correct
92 Incorrect 236 ms 55780 KB Output isn't correct
93 Incorrect 250 ms 55988 KB Output isn't correct
94 Incorrect 233 ms 55864 KB Output isn't correct
95 Incorrect 229 ms 55856 KB Output isn't correct
96 Incorrect 233 ms 55856 KB Output isn't correct
97 Incorrect 244 ms 55756 KB Output isn't correct
98 Incorrect 233 ms 55752 KB Output isn't correct
99 Incorrect 246 ms 55884 KB Output isn't correct
100 Incorrect 239 ms 55848 KB Output isn't correct