답안 #377411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377411 2021-03-14T07:37:05 Z VEGAnn Selotejp (COCI20_selotejp) C++14
110 / 110
961 ms 4460 KB
#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int N = 1010;
const int M = 10;
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 89 ms 4076 KB Output is correct
3 Correct 17 ms 4076 KB Output is correct
4 Correct 44 ms 4332 KB Output is correct
5 Correct 100 ms 4332 KB Output is correct
6 Correct 99 ms 4460 KB Output is correct
7 Correct 100 ms 4204 KB Output is correct
8 Correct 88 ms 4076 KB Output is correct
9 Correct 90 ms 4076 KB Output is correct
10 Correct 184 ms 4332 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 1 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 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 89 ms 4076 KB Output is correct
3 Correct 17 ms 4076 KB Output is correct
4 Correct 44 ms 4332 KB Output is correct
5 Correct 100 ms 4332 KB Output is correct
6 Correct 99 ms 4460 KB Output is correct
7 Correct 100 ms 4204 KB Output is correct
8 Correct 88 ms 4076 KB Output is correct
9 Correct 90 ms 4076 KB Output is correct
10 Correct 184 ms 4332 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 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 20 ms 4332 KB Output is correct
21 Correct 44 ms 4332 KB Output is correct
22 Correct 90 ms 4204 KB Output is correct
23 Correct 92 ms 4204 KB Output is correct
24 Correct 96 ms 4204 KB Output is correct
25 Correct 109 ms 4204 KB Output is correct
26 Correct 227 ms 4204 KB Output is correct
27 Correct 521 ms 4172 KB Output is correct
28 Correct 961 ms 4304 KB Output is correct