답안 #878868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878868 2023-11-25T11:18:07 Z Gray Bomb (IZhO17_bomb) C++17
0 / 100
86 ms 131072 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
#include <cassert>
#define ll long long
#define ln "\n"
#define ff first
#define ss second
#define ld long double
const ll INF = 2e18;
const ll MOD = 1e9+7;
using namespace std;

void solve(){
	ll n, m; cin >> n >> m;
	vector<vector<char>> grid(n, vector<char>(m));
	for (ll i=0; i<n; i++){
		for (ll j=0; j<m; j++) cin >> grid[i][j];
	}
	vector<vector<ll>> dist(n, vector<ll>(m, 0));
	for (ll i=0; i<n; i++){
		ll loj = -1;
		for (ll j=0; j<m; j++){
			if (grid[i][j] == '0'){
				loj = j;
			}
			dist[i][j] = j-loj;
		}
	}
	vector<vector<pair<ll, ll>>> reqs(n, vector<pair<ll, ll>>(m));
	for (ll j=0; j<m; j++){
		vector<ll> tpdi(n);
		stack<ll> mni;
		for (ll i=0; i<n; i++){
			while (!mni.empty() and dist[mni.top()][j]>=dist[i][j]) mni.pop();
			if (!mni.empty()) tpdi[i] = i-mni.top();
			else tpdi[i] = i+1;
			mni.push(i);
		}
		mni = stack<ll>();
		for (ll i = n-1; i>=0; i--){
			ll tdp = 0;
			while (!mni.empty() and dist[mni.top()][j]>=dist[i][j]) mni.pop();
			if (!mni.empty()){
				// cout << mni.top() << ln;
				tdp = mni.top()-i;
			}else tdp = n-i;
			mni.push(i);
			// if (grid[i][j]=='0') continue;
			reqs[i][j] = {dist[i][j], tdp+tpdi[i]-1};
			// cout << i << " " << j << ": " << dist[i][j] << " ; " << tdp << " " << tpdi[i] << ln;
		}
	}
	ll mnw = m, mnh = n;
	for (ll i=0; i<n; i++){
		for (ll j=0; j<m; j++){
			if (grid[i][j]=='1' and (j+1==m or grid[i][j+1]=='0')){
				mnw = min(mnw, reqs[i][j].ff);
				mnh = min(mnh, reqs[i][j].ss);
			}
		}
	}
	cout << mnw*mnh << ln;
}
void setIO(){
	// ios_base::sync_with_stdio(false);
	// cin.tie(nullptr);
	// cout.tie(nullptr);
    freopen("bomb.in", "r", stdin);
    freopen("bomb.out", "w", stdout);
}
int main(){
	setIO();
	ll t=1;
    // cin >> t;
    while (t--) solve();
}

Compilation message

bomb.cpp: In function 'void setIO()':
bomb.cpp:69:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     freopen("bomb.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bomb.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen("bomb.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 86 ms 131072 KB Execution killed with signal 9
2 Runtime error 61 ms 131072 KB Execution killed with signal 9
3 Runtime error 61 ms 131072 KB Execution killed with signal 9
4 Runtime error 62 ms 131072 KB Execution killed with signal 9
5 Runtime error 63 ms 131072 KB Execution killed with signal 9
6 Runtime error 62 ms 131072 KB Execution killed with signal 9
7 Runtime error 74 ms 131072 KB Execution killed with signal 9
8 Runtime error 61 ms 131072 KB Execution killed with signal 9
9 Runtime error 72 ms 131072 KB Execution killed with signal 9
10 Runtime error 61 ms 131072 KB Execution killed with signal 9
11 Runtime error 62 ms 131072 KB Execution killed with signal 9
12 Runtime error 66 ms 131072 KB Execution killed with signal 9
13 Runtime error 60 ms 131072 KB Execution killed with signal 9
14 Runtime error 61 ms 131072 KB Execution killed with signal 9
15 Runtime error 63 ms 131072 KB Execution killed with signal 9
16 Runtime error 62 ms 131072 KB Execution killed with signal 9
17 Runtime error 64 ms 131072 KB Execution killed with signal 9
18 Runtime error 60 ms 131072 KB Execution killed with signal 9
19 Runtime error 61 ms 131072 KB Execution killed with signal 9
20 Runtime error 62 ms 131072 KB Execution killed with signal 9
21 Runtime error 62 ms 131072 KB Execution killed with signal 9
22 Runtime error 60 ms 131072 KB Execution killed with signal 9
23 Runtime error 72 ms 131072 KB Execution killed with signal 9
24 Runtime error 62 ms 131072 KB Execution killed with signal 9
25 Runtime error 62 ms 131072 KB Execution killed with signal 9
26 Runtime error 61 ms 131072 KB Execution killed with signal 9
27 Runtime error 64 ms 131072 KB Execution killed with signal 9
28 Runtime error 61 ms 131072 KB Execution killed with signal 9
29 Runtime error 61 ms 131072 KB Execution killed with signal 9
30 Runtime error 62 ms 131072 KB Execution killed with signal 9
31 Runtime error 61 ms 131072 KB Execution killed with signal 9
32 Runtime error 73 ms 131072 KB Execution killed with signal 9
33 Runtime error 63 ms 131072 KB Execution killed with signal 9
34 Runtime error 62 ms 131072 KB Execution killed with signal 9
35 Runtime error 61 ms 131072 KB Execution killed with signal 9
36 Runtime error 73 ms 131072 KB Execution killed with signal 9
37 Runtime error 64 ms 131072 KB Execution killed with signal 9
38 Runtime error 64 ms 131072 KB Execution killed with signal 9
39 Runtime error 61 ms 131072 KB Execution killed with signal 9
40 Runtime error 64 ms 131072 KB Execution killed with signal 9
41 Runtime error 64 ms 131072 KB Execution killed with signal 9
42 Runtime error 60 ms 131072 KB Execution killed with signal 9
43 Runtime error 62 ms 131072 KB Execution killed with signal 9
44 Runtime error 62 ms 131072 KB Execution killed with signal 9
45 Runtime error 68 ms 131072 KB Execution killed with signal 9
46 Runtime error 61 ms 131072 KB Execution killed with signal 9
47 Runtime error 62 ms 131072 KB Execution killed with signal 9
48 Runtime error 66 ms 131072 KB Execution killed with signal 9
49 Runtime error 64 ms 131072 KB Execution killed with signal 9
50 Runtime error 84 ms 131072 KB Execution killed with signal 9
51 Runtime error 62 ms 131072 KB Execution killed with signal 9
52 Runtime error 62 ms 131072 KB Execution killed with signal 9
53 Runtime error 61 ms 131072 KB Execution killed with signal 9
54 Runtime error 63 ms 131072 KB Execution killed with signal 9
55 Runtime error 64 ms 131072 KB Execution killed with signal 9
56 Runtime error 64 ms 131072 KB Execution killed with signal 9
57 Runtime error 61 ms 131072 KB Execution killed with signal 9
58 Runtime error 71 ms 131072 KB Execution killed with signal 9
59 Runtime error 62 ms 131072 KB Execution killed with signal 9
60 Runtime error 62 ms 131072 KB Execution killed with signal 9
61 Runtime error 62 ms 131072 KB Execution killed with signal 9
62 Runtime error 62 ms 131072 KB Execution killed with signal 9
63 Runtime error 66 ms 131072 KB Execution killed with signal 9
64 Runtime error 61 ms 131072 KB Execution killed with signal 9
65 Runtime error 62 ms 131072 KB Execution killed with signal 9
66 Runtime error 61 ms 131072 KB Execution killed with signal 9
67 Runtime error 63 ms 131072 KB Execution killed with signal 9
68 Runtime error 62 ms 131072 KB Execution killed with signal 9
69 Runtime error 59 ms 131072 KB Execution killed with signal 9
70 Runtime error 61 ms 131072 KB Execution killed with signal 9
71 Runtime error 64 ms 131072 KB Execution killed with signal 9
72 Runtime error 61 ms 131072 KB Execution killed with signal 9
73 Runtime error 75 ms 131072 KB Execution killed with signal 9
74 Runtime error 86 ms 131072 KB Execution killed with signal 9
75 Runtime error 75 ms 131072 KB Execution killed with signal 9
76 Runtime error 67 ms 131072 KB Execution killed with signal 9
77 Runtime error 62 ms 131072 KB Execution killed with signal 9
78 Runtime error 65 ms 131072 KB Execution killed with signal 9
79 Runtime error 64 ms 131072 KB Execution killed with signal 9
80 Runtime error 67 ms 131072 KB Execution killed with signal 9
81 Runtime error 60 ms 131072 KB Execution killed with signal 9
82 Runtime error 62 ms 131072 KB Execution killed with signal 9
83 Runtime error 60 ms 131072 KB Execution killed with signal 9
84 Runtime error 66 ms 131072 KB Execution killed with signal 9
85 Runtime error 60 ms 131072 KB Execution killed with signal 9
86 Runtime error 66 ms 131072 KB Execution killed with signal 9
87 Runtime error 60 ms 131072 KB Execution killed with signal 9
88 Runtime error 84 ms 131072 KB Execution killed with signal 9
89 Runtime error 63 ms 131072 KB Execution killed with signal 9
90 Runtime error 62 ms 131072 KB Execution killed with signal 9
91 Runtime error 67 ms 131072 KB Execution killed with signal 9
92 Runtime error 66 ms 131072 KB Execution killed with signal 9
93 Runtime error 63 ms 131072 KB Execution killed with signal 9
94 Runtime error 64 ms 131072 KB Execution killed with signal 9
95 Runtime error 62 ms 131072 KB Execution killed with signal 9
96 Runtime error 64 ms 131072 KB Execution killed with signal 9
97 Runtime error 74 ms 131072 KB Execution killed with signal 9
98 Runtime error 60 ms 131072 KB Execution killed with signal 9
99 Runtime error 62 ms 131072 KB Execution killed with signal 9
100 Runtime error 62 ms 131072 KB Execution killed with signal 9