답안 #377410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377410 2021-03-14T07:35:52 Z VEGAnn Selotejp (COCI20_selotejp) C++14
110 / 110
947 ms 8428 KB
#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int N = 1010;
const int M = 11;
const int PW = 10;
const int HPW = 233;
const int md = int(1e9) + 7;
int f[N][(1 << M)], n, m;
string s;

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 0; i <= n; i++)
    for (int j = 0; j < (1 << m); j++)
        f[i][j] = oo;

    f[0][0] = 0;

    for (int i = 1; i <= n; i++){
        cin >> s;

        int cur = 0;

        for (int j = 0; j < m; j++)
            if (s[j] == '#')
                cur += (1 << j);

        for (int old = 0; old < (1 << m); old++)
        for (int msk = old; ; msk = ((msk - 1) & old)){
            f[i - 1][msk] = min(f[i - 1][msk], f[i - 1][old]);

            if (msk == 0) break;
        }

        for (int nw = 0; nw < (1 << m); nw++){
            bool ok = 1;

            for (int j = 0; j < m; j++)
                if (s[j] == '.' && (nw & (1 << j))){
                    ok = 0;
                    break;
                }

            if (!ok) continue;

            for (int pre = nw; ; pre = ((pre - 1) & nw)){
                int nf = f[i - 1][pre];

                if (nf == oo) {
                    if (pre == 0)
                        break;

                    continue;
                }

                for (int j = 0; j < m; j++)
                    if (nw & (1 << j)){
                        if (!(pre & (1 << j)))
                            nf++;
                    } else {
                        if (cur & (1 << j)){
                            if (!(j > 0 && (cur & (1 << (j - 1))) && (!(nw & (1 << (j - 1))))))
                                nf++;
                        }
                    }

                f[i][nw] = min(f[i][nw], nf);

                if (pre == 0) break;
            }
        }
    }

    int ans = oo;

    for (int msk = 0; msk < (1 << m); msk++)
        ans = min(ans, f[n][msk]);

    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 94 ms 7660 KB Output is correct
3 Correct 16 ms 4076 KB Output is correct
4 Correct 40 ms 4204 KB Output is correct
5 Correct 99 ms 8172 KB Output is correct
6 Correct 104 ms 8300 KB Output is correct
7 Correct 97 ms 8044 KB Output is correct
8 Correct 89 ms 7788 KB Output is correct
9 Correct 94 ms 7916 KB Output is correct
10 Correct 161 ms 8428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 94 ms 7660 KB Output is correct
3 Correct 16 ms 4076 KB Output is correct
4 Correct 40 ms 4204 KB Output is correct
5 Correct 99 ms 8172 KB Output is correct
6 Correct 104 ms 8300 KB Output is correct
7 Correct 97 ms 8044 KB Output is correct
8 Correct 89 ms 7788 KB Output is correct
9 Correct 94 ms 7916 KB Output is correct
10 Correct 161 ms 8428 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 4 ms 4204 KB Output is correct
20 Correct 19 ms 4332 KB Output is correct
21 Correct 44 ms 4332 KB Output is correct
22 Correct 93 ms 8044 KB Output is correct
23 Correct 93 ms 8044 KB Output is correct
24 Correct 94 ms 8044 KB Output is correct
25 Correct 113 ms 8172 KB Output is correct
26 Correct 218 ms 7916 KB Output is correct
27 Correct 525 ms 8044 KB Output is correct
28 Correct 947 ms 8428 KB Output is correct