답안 #445521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445521 2021-07-18T13:15:06 Z grt Selotejp (COCI20_selotejp) C++17
110 / 110
42 ms 348 KB
#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back

using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 1010, INF = 1e9;
int n, m;
char t[nax][12];
vi dp, dp2;


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int j = 1; j <= m; ++j) t[0][j] = '.';
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> t[i][j];
		}
	}
	int pt = 1;
	for(int i = 0; i < m; ++i) pt *= 2;
	dp.resize(pt);
	dp2.resize(pt);
	for(int i = 1; i <= n; ++i) {
		int cur = 1;
		t[i][0] = '.';
		for(int j = 1; j <= m; ++j) {
			for(int mask = 0; mask < pt; ++mask) {	
				if(t[i][j] == '.') {
					dp[mask] = min(dp2[mask], dp2[mask ^ cur]);
				} else {
					dp[mask] = INF;
					if(mask & cur) {
						if(t[i - 1][j] == '#') {
							dp[mask] = min(dp[mask], dp2[mask]);
						}
					} else if(cur > 1 && (mask & (cur / 2)) == 0){
						if(t[i][j - 1] == '#') {
							dp[mask] = min(dp[mask], min(dp2[mask], dp2[mask ^ cur]));
						}
					}
					dp[mask] = min({dp[mask], dp2[mask] + 1, dp2[mask ^ cur] + 1});
				}
			}
			dp.swap(dp2);
			cur *= 2;
		}
	}
	int ans = INF;
	for(int i = 0; i < pt; ++i) {
		ans = min(ans, dp2[i]);
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 23 ms 344 KB Output is correct
7 Correct 21 ms 340 KB Output is correct
8 Correct 17 ms 348 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
10 Correct 25 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 248 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 21 ms 344 KB Output is correct
6 Correct 23 ms 344 KB Output is correct
7 Correct 21 ms 340 KB Output is correct
8 Correct 17 ms 348 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
10 Correct 25 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 248 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 6 ms 332 KB Output is correct
21 Correct 12 ms 340 KB Output is correct
22 Correct 17 ms 344 KB Output is correct
23 Correct 17 ms 340 KB Output is correct
24 Correct 19 ms 344 KB Output is correct
25 Correct 24 ms 340 KB Output is correct
26 Correct 30 ms 332 KB Output is correct
27 Correct 33 ms 332 KB Output is correct
28 Correct 42 ms 332 KB Output is correct