답안 #542043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542043 2022-03-25T08:43:07 Z AlperenT Selotejp (COCI20_selotejp) C++17
110 / 110
44 ms 40396 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1000 + 5, M = 10, K = 1 << M;

int n, m, dp[N][M][K];

char arr[N][M];

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

    cin >> n >> m;

    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++){
            cin >> arr[i][j];
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j = 0; j < m; j++){
            for(int msk = 0; msk < (1 << m); msk++){
                if(j == 0){
                    if(msk & (1 << j)){
                        dp[i][j][msk] = min(dp[i - 1][m - 1][msk] + (arr[i][j] == '#' && arr[i - 1][j] != '#'), dp[i - 1][m - 1][msk ^ (1 << j)] + (arr[i][j] == '#'));
                    }
                    else{
                        dp[i][j][msk] = min(dp[i - 1][m - 1][msk], dp[i - 1][m - 1][msk ^ (1 << j)]) + (arr[i][j] == '#');
                    }
                }
                else{
                    if(msk & (1 << j)){
                        dp[i][j][msk] = min(dp[i][j - 1][msk] + (arr[i][j] == '#' && arr[i - 1][j] != '#'), dp[i][j - 1][msk ^ (1 << j)] + (arr[i][j] == '#'));
                    }
                    else{
                        if(!(msk & (1 << (j - 1)))){
                            dp[i][j][msk] = min(dp[i][j - 1][msk], dp[i][j - 1][msk ^ (1 << j)]) + (arr[i][j] == '#' && arr[i][j - 1] != '#');
                        }
                        else{
                            dp[i][j][msk] = min(dp[i][j - 1][msk], dp[i][j - 1][msk ^ (1 << j)]) + (arr[i][j] == '#');
                        }
                    }
                }
            }
        }
    }

    cout << *min_element(dp[n][m - 1], dp[n][m - 1] + (1 << m));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 34 ms 37192 KB Output is correct
3 Correct 18 ms 33492 KB Output is correct
4 Correct 25 ms 39192 KB Output is correct
5 Correct 35 ms 39656 KB Output is correct
6 Correct 34 ms 39884 KB Output is correct
7 Correct 34 ms 38860 KB Output is correct
8 Correct 31 ms 37156 KB Output is correct
9 Correct 35 ms 37452 KB Output is correct
10 Correct 39 ms 40396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 34 ms 37192 KB Output is correct
3 Correct 18 ms 33492 KB Output is correct
4 Correct 25 ms 39192 KB Output is correct
5 Correct 35 ms 39656 KB Output is correct
6 Correct 34 ms 39884 KB Output is correct
7 Correct 34 ms 38860 KB Output is correct
8 Correct 31 ms 37156 KB Output is correct
9 Correct 35 ms 37452 KB Output is correct
10 Correct 39 ms 40396 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 720 KB Output is correct
19 Correct 8 ms 19668 KB Output is correct
20 Correct 18 ms 36052 KB Output is correct
21 Correct 25 ms 40328 KB Output is correct
22 Correct 44 ms 39100 KB Output is correct
23 Correct 35 ms 38880 KB Output is correct
24 Correct 44 ms 38540 KB Output is correct
25 Correct 35 ms 39524 KB Output is correct
26 Correct 35 ms 37864 KB Output is correct
27 Correct 35 ms 37964 KB Output is correct
28 Correct 41 ms 39344 KB Output is correct