답안 #557241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557241 2022-05-05T00:34:36 Z CyberSleeper Selotejp (COCI20_selotejp) C++17
110 / 110
35 ms 44564 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x)      x.begin(), x.end()
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ull         unsigned long long
#define pll         pair<ll, ll>
#define pii         pair<ll, ll>
#define ld          long double
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
#define sqr(x)      (x)*(x)
#define sz          take.size()
#define arr3        array<int, 3>
#define calc(x, y)  (sqr(X[x]-X[y])+sqr(Y[x]-Y[y]))
using namespace std;

const ll MX=1005, MOD=1000000007, BLOCK=327, INF=2e9+7;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;

int N, M, DP[MX][12][1030], ans=INF;
string A[MX];

int main(){
    fastio;
    cin >> N >> M;
    for(int i=1; i<=N; i++){
        cin >> A[i];
    }
    for(int j=0; j<M; j++){
        for(int mask=0; mask<(1<<M); mask++)
            DP[0][j][mask]=INF;
    }
    DP[0][M-1][0]=0;
    A[0]=string(M, '.');
    for(int i=1; i<=N; i++){
        for(int j=0; j<M; j++){
            for(int mask=0; mask<(1<<M); mask++){
                int x=i, y=j-1;
                if(y<0)
                    x=i-1, y=M-1;
                if(mask&(1<<j)){
                    if(A[i][j]=='.'){
                        DP[i][j][mask]=INF;
                    }else{
                        DP[i][j][mask]=min(DP[x][y][mask^(1<<j)]+1, DP[x][y][mask]);
                    }
                }else{
                    DP[i][j][mask]=min(DP[x][y][mask], DP[x][y][mask^(1<<j)]);
                    if(A[i][j]=='#'){
                        if(j==0 || A[i][j-1]=='.' || (mask&(1<<(j-1))))
                            DP[i][j][mask]++;
                    }
                }
            }
        }
    }
    for(int mask=0; mask<(1<<M); mask++)
        ans=min(ans, DP[N][M-1][mask]);
    cout << ans << nl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 27 ms 41172 KB Output is correct
3 Correct 14 ms 30932 KB Output is correct
4 Correct 20 ms 37400 KB Output is correct
5 Correct 31 ms 43988 KB Output is correct
6 Correct 31 ms 44116 KB Output is correct
7 Correct 31 ms 42964 KB Output is correct
8 Correct 27 ms 41072 KB Output is correct
9 Correct 30 ms 41336 KB Output is correct
10 Correct 31 ms 44564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 756 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 27 ms 41172 KB Output is correct
3 Correct 14 ms 30932 KB Output is correct
4 Correct 20 ms 37400 KB Output is correct
5 Correct 31 ms 43988 KB Output is correct
6 Correct 31 ms 44116 KB Output is correct
7 Correct 31 ms 42964 KB Output is correct
8 Correct 27 ms 41072 KB Output is correct
9 Correct 30 ms 41336 KB Output is correct
10 Correct 31 ms 44564 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 756 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 8 ms 19924 KB Output is correct
20 Correct 17 ms 33260 KB Output is correct
21 Correct 21 ms 38688 KB Output is correct
22 Correct 28 ms 43188 KB Output is correct
23 Correct 28 ms 42964 KB Output is correct
24 Correct 29 ms 42704 KB Output is correct
25 Correct 31 ms 43756 KB Output is correct
26 Correct 32 ms 41880 KB Output is correct
27 Correct 33 ms 42016 KB Output is correct
28 Correct 35 ms 43412 KB Output is correct