# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
367824 | 2021-02-18T13:20:56 Z | phathnv | Selotejp (COCI20_selotejp) | C++11 | 42 ms | 512 KB |
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Selotejp" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int M = 1001; const int N = 10; const int INF = 1e9; void minimize(int &x, int y){ if (x > y) x = y; } int m, n, closedInRow[M], dp[2][1 << N], f[1 << N], cost[1 << N]; void readInput(){ cin >> m >> n; for(int i = 1; i <= m; i++){ string s; cin >> s; for(int j = 0; j < n; j++) if (s[j] == '#') closedInRow[i] |= (1 << j); } } void solve(){ for(int mask = 0; mask < (1 << n); mask++){ cost[mask] = 0; for(int i = 0; i < n; i++){ cost[mask] += (mask >> i) & 1; if (i > 0) cost[mask] -= (mask >> (i - 1)) & (mask >> i) & 1; } } for(int id = 0; id < 2; id++) for(int mask = 0; mask < (1 << n); mask++) dp[id][mask] = INF; dp[0][0] = 0; for(int i = 1; i <= m; i++){ int id = i & 1; for(int mask = 0; mask < (1 << n); mask++) f[mask] = dp[id][mask] = INF; for(int mask = 0; mask < (1 << n); mask++) minimize(f[mask & closedInRow[i]], dp[id ^ 1][mask]); for(int mask = 0; mask < (1 << n); mask++) for(int j = 0; j < n; j++) minimize(f[mask | (1 << j)], f[mask] + 1); for(int mask = (1 << n) - 1; mask >= 0; mask--) for(int j = 0; j < n; j++) minimize(f[mask & (~(1 << j))], f[mask]); for(int mask = 0; mask < (1 << n); mask++){ if ((closedInRow[i] & mask) != mask) continue; dp[id][mask] = f[mask] + cost[closedInRow[i] ^ mask]; } } int res = INF; for(int mask = 0; mask < (1 << n); mask++) res = min(res, dp[m & 1][mask]); cout << res; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(nullptr); readInput(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 512 KB | Output is correct |
2 | Correct | 29 ms | 492 KB | Output is correct |
3 | Correct | 6 ms | 364 KB | Output is correct |
4 | Correct | 15 ms | 364 KB | Output is correct |
5 | Correct | 31 ms | 364 KB | Output is correct |
6 | Correct | 32 ms | 492 KB | Output is correct |
7 | Correct | 30 ms | 384 KB | Output is correct |
8 | Correct | 30 ms | 364 KB | Output is correct |
9 | Correct | 30 ms | 364 KB | Output is correct |
10 | Correct | 42 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 512 KB | Output is correct |
2 | Correct | 29 ms | 492 KB | Output is correct |
3 | Correct | 6 ms | 364 KB | Output is correct |
4 | Correct | 15 ms | 364 KB | Output is correct |
5 | Correct | 31 ms | 364 KB | Output is correct |
6 | Correct | 32 ms | 492 KB | Output is correct |
7 | Correct | 30 ms | 384 KB | Output is correct |
8 | Correct | 30 ms | 364 KB | Output is correct |
9 | Correct | 30 ms | 364 KB | Output is correct |
10 | Correct | 42 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 2 ms | 512 KB | Output is correct |
20 | Correct | 9 ms | 364 KB | Output is correct |
21 | Correct | 17 ms | 424 KB | Output is correct |
22 | Correct | 34 ms | 424 KB | Output is correct |
23 | Correct | 36 ms | 364 KB | Output is correct |
24 | Correct | 31 ms | 364 KB | Output is correct |
25 | Correct | 32 ms | 364 KB | Output is correct |
26 | Correct | 33 ms | 424 KB | Output is correct |
27 | Correct | 34 ms | 364 KB | Output is correct |
28 | Correct | 36 ms | 384 KB | Output is correct |