Submission #376676

# Submission time Handle Problem Language Result Execution time Memory
376676 2021-03-12T01:21:07 Z lyc Selotejp (COCI20_selotejp) C++14
110 / 110
58 ms 40428 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = 1000;
const int mxM = 10;

int N, M;
string G[mxN];
int dp[mxN+1][mxM][1<<mxM];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> N >> M;
    FOR(i,0,N-1){
        cin >> G[i];
    }

    RFOR(i,N-1,0){
        RFOR(j,M-1,0){
            FOR(x,0,(1<<M)-1){
                if (G[i][j] == '.') {
                    dp[i][j][x] = dp[i+(j+1)/M][(j+1)%M][x];
                } else {
                    // 1 v 0 h
                    dp[i][j][x] = min(
                        dp[i+(j+1)/M][(j+1)%M][x|(1<<j)] + (i==0 || G[i-1][j]=='.' || (x&(1<<j))==0),
                        dp[i+(j+1)/M][(j+1)%M][x&(~(1<<j))] + (j==0 || G[i][j-1]=='.' || (x&(1<<(j-1)))>0)
                    );
                }
                //TRACE(i _ j _ x _ dp[i][j][x]);
            }}}

    cout << dp[0][0][0] << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 34 ms 37356 KB Output is correct
3 Correct 20 ms 29932 KB Output is correct
4 Correct 26 ms 35436 KB Output is correct
5 Correct 38 ms 39788 KB Output is correct
6 Correct 39 ms 39916 KB Output is correct
7 Correct 40 ms 39020 KB Output is correct
8 Correct 33 ms 37356 KB Output is correct
9 Correct 37 ms 37484 KB Output is correct
10 Correct 44 ms 40428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 34 ms 37356 KB Output is correct
3 Correct 20 ms 29932 KB Output is correct
4 Correct 26 ms 35436 KB Output is correct
5 Correct 38 ms 39788 KB Output is correct
6 Correct 39 ms 39916 KB Output is correct
7 Correct 40 ms 39020 KB Output is correct
8 Correct 33 ms 37356 KB Output is correct
9 Correct 37 ms 37484 KB Output is correct
10 Correct 44 ms 40428 KB Output is correct
11 Correct 1 ms 748 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 748 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 876 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 640 KB Output is correct
18 Correct 1 ms 748 KB Output is correct
19 Correct 11 ms 19948 KB Output is correct
20 Correct 22 ms 32108 KB Output is correct
21 Correct 29 ms 36460 KB Output is correct
22 Correct 31 ms 39148 KB Output is correct
23 Correct 34 ms 38892 KB Output is correct
24 Correct 36 ms 38636 KB Output is correct
25 Correct 43 ms 39660 KB Output is correct
26 Correct 50 ms 38016 KB Output is correct
27 Correct 53 ms 38124 KB Output is correct
28 Correct 58 ms 39404 KB Output is correct