답안 #1019423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019423 2024-07-10T20:00:45 Z ilovveyyou Selotejp (COCI20_selotejp) C++14
110 / 110
938 ms 8792 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define clz __builtin_clzll
#define ctz __builtin_ctzll
#define popcount __builtin_popcount
#define lg(x) (63 - clz(x))

template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        if (x < y) return x = y, true;
        return false;
    }
template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        if (x > y) return x = y, true;
        return false;
    }
template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a)); a.resize(unique(all(a)) - a.begin());
    }

const ll oo = (ll) 1e17;
const int inf = (int) 1e9, mod = (int) 1e9 + 7;

const int mxn = (int) 1e3 + 5, mxm = (int) 11;
int n, m;
int a[mxn][mxm];

int subMask[mxn];
int f[mxn][MASK(mxm)];

int stack_mask[MASK(mxm)];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    for (int j = 0; j < m; ++j) {
        char c; cin >> c;
        a[i][j] = (c == '#');
        subMask[i] += a[i][j] * MASK(j);
    }

    for (int mask = 0; mask < MASK(m); ++mask) {
        bool ok = false;
        for (int i = 0; i < m; ++i) {
            if (BIT(mask, i)) ok = true;
            else {
                if (ok) stack_mask[mask]++;
                ok = false;
            }
        }
        if (ok) stack_mask[mask]++;
    }

    memset(f, 0x3f, sizeof f);

    f[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int mask = 0; mask < MASK(m); ++mask) if (f[i][mask] < inf) {
            int rev = ~mask & (MASK(m) - 1) & subMask[i+1];
            for (int sub = rev; ; sub = (sub - 1) & rev) {
                int cur = mask & subMask[i+1];
                for (int sub_mask = cur; ; sub_mask = (sub_mask - 1) & cur) {
                    minimize(f[i+1][sub | sub_mask], f[i][mask] + popcount(sub));
                    if (sub_mask == 0) break;
                }
                if (sub == 0) break;
            }
        }
        for (int mask = 0; mask < MASK(m); ++mask) {
            int rev = ~mask & (MASK(m) - 1);
            rev &= subMask[i+1];
            f[i+1][mask] += stack_mask[rev];
        }
    }

    int ans = inf;
    for (int mask = 0; mask < MASK(m); ++mask)
        minimize(ans, f[n][mask]);

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 5 ms 8584 KB Output is correct
3 Correct 4 ms 8540 KB Output is correct
4 Correct 5 ms 8516 KB Output is correct
5 Correct 5 ms 8540 KB Output is correct
6 Correct 6 ms 8580 KB Output is correct
7 Correct 8 ms 8536 KB Output is correct
8 Correct 6 ms 8792 KB Output is correct
9 Correct 6 ms 8520 KB Output is correct
10 Correct 8 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8400 KB Output is correct
3 Correct 3 ms 8284 KB Output is correct
4 Correct 4 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8280 KB Output is correct
7 Correct 3 ms 8284 KB Output is correct
8 Correct 4 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 5 ms 8584 KB Output is correct
3 Correct 4 ms 8540 KB Output is correct
4 Correct 5 ms 8516 KB Output is correct
5 Correct 5 ms 8540 KB Output is correct
6 Correct 6 ms 8580 KB Output is correct
7 Correct 8 ms 8536 KB Output is correct
8 Correct 6 ms 8792 KB Output is correct
9 Correct 6 ms 8520 KB Output is correct
10 Correct 8 ms 8540 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8400 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 4 ms 8284 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8280 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 4 ms 8280 KB Output is correct
19 Correct 4 ms 8540 KB Output is correct
20 Correct 5 ms 8540 KB Output is correct
21 Correct 6 ms 8580 KB Output is correct
22 Correct 5 ms 8540 KB Output is correct
23 Correct 5 ms 8540 KB Output is correct
24 Correct 5 ms 8540 KB Output is correct
25 Correct 11 ms 8540 KB Output is correct
26 Correct 95 ms 8540 KB Output is correct
27 Correct 401 ms 8556 KB Output is correct
28 Correct 938 ms 8540 KB Output is correct