Submission #1005271

# Submission time Handle Problem Language Result Execution time Memory
1005271 2024-06-22T09:32:35 Z TrinhKhanhDung Selotejp (COCI20_selotejp) C++14
110 / 110
38 ms 57556 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAXN = 1e3 + 10, MAXM = 13;

int N, M;
int a[MAXN][MAXN], f[MAXN][MAXM][MASK(10) + 10];

void solve(){
    cin >> N >> M;
    for(int i=1; i<=N; i++){
        string s; cin >> s;
        for(int j=0; j<M; j++){
            a[i][j + 1] = s[j] == '#';
        }
    }
    memset(f, 0x3f, sizeof f);
    memset(f[0][M], 0, sizeof f[0][M]);
    for(int i=1; i<=N; i++){
        for(int mask=0; mask<MASK(M); mask++){
            f[i][0][mask] = f[i - 1][M][mask];
        }

        for(int j=1; j<=M; j++){
            for(int mask=0; mask<MASK(M); mask++){
                if(!a[i][j]){f[i][j][mask] = f[i][j - 1][mask]; continue;}
                if(!BIT(mask, j - 1)){
                    if(j > 1 && !BIT(mask, j - 2) && a[i][j - 1]){
                        f[i][j][mask] = min(f[i][j - 1][mask], f[i][j - 1][mask ^ MASK(j - 1)]);
                    }
                    else{
                        f[i][j][mask] = min(f[i][j - 1][mask], f[i][j - 1][mask ^ MASK(j - 1)]) + 1;
                    }
                }
                else{
                    f[i][j][mask] = min(f[i][j - 1][mask], f[i][j - 1][mask ^ MASK(j - 1)]) + 1;
                    if(a[i - 1][j]) minimize(f[i][j][mask], f[i][j - 1][mask]);
                }
            }
        }
    }

    int ans = INF;
    for(int mask=0; mask<MASK(M); mask++){
        minimize(ans, f[N][M][mask]);
    }
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen("netw.inp", "r", stdin);
//    freopen("netw.out", "w", stdout);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 53972 KB Output is correct
2 Correct 21 ms 57180 KB Output is correct
3 Correct 14 ms 57180 KB Output is correct
4 Correct 14 ms 57432 KB Output is correct
5 Correct 28 ms 57436 KB Output is correct
6 Correct 21 ms 57432 KB Output is correct
7 Correct 22 ms 57180 KB Output is correct
8 Correct 19 ms 57176 KB Output is correct
9 Correct 20 ms 57180 KB Output is correct
10 Correct 38 ms 57556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 53852 KB Output is correct
2 Correct 9 ms 53988 KB Output is correct
3 Correct 7 ms 53852 KB Output is correct
4 Correct 7 ms 53852 KB Output is correct
5 Correct 8 ms 53932 KB Output is correct
6 Correct 7 ms 53852 KB Output is correct
7 Correct 8 ms 53852 KB Output is correct
8 Correct 7 ms 53852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 53972 KB Output is correct
2 Correct 21 ms 57180 KB Output is correct
3 Correct 14 ms 57180 KB Output is correct
4 Correct 14 ms 57432 KB Output is correct
5 Correct 28 ms 57436 KB Output is correct
6 Correct 21 ms 57432 KB Output is correct
7 Correct 22 ms 57180 KB Output is correct
8 Correct 19 ms 57176 KB Output is correct
9 Correct 20 ms 57180 KB Output is correct
10 Correct 38 ms 57556 KB Output is correct
11 Correct 8 ms 53852 KB Output is correct
12 Correct 9 ms 53988 KB Output is correct
13 Correct 7 ms 53852 KB Output is correct
14 Correct 7 ms 53852 KB Output is correct
15 Correct 8 ms 53932 KB Output is correct
16 Correct 7 ms 53852 KB Output is correct
17 Correct 8 ms 53852 KB Output is correct
18 Correct 7 ms 53852 KB Output is correct
19 Correct 8 ms 57180 KB Output is correct
20 Correct 13 ms 57436 KB Output is correct
21 Correct 18 ms 57432 KB Output is correct
22 Correct 19 ms 57376 KB Output is correct
23 Correct 33 ms 57176 KB Output is correct
24 Correct 20 ms 57176 KB Output is correct
25 Correct 22 ms 57436 KB Output is correct
26 Correct 23 ms 57180 KB Output is correct
27 Correct 24 ms 57252 KB Output is correct
28 Correct 28 ms 57436 KB Output is correct