답안 #704992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704992 2023-03-03T07:40:49 Z 1075508020060209tc Selotejp (COCI20_selotejp) C++14
70 / 110
1000 ms 16592 KB
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define X first
#define Y second
int n;int m;
string tgr[1010];
int dp[1010][3010];
int gr[1010];
int col[3010];
int sme[3010][3010];
int bts[3010];

signed main(){

cin>>n>>m;
for(int i=1;i<=n;i++){
    cin>>tgr[i];
}
for(int i=1;i<=n;i++){
    for(int j=0;j<m;j++){
        if(tgr[i][j]=='#'){
            gr[i]+=(1<<j);
        }
    }
}

for(int i=0;i<(1<<m);i++){
    for(int j=0;j<m;j++){
        if( ((i&(1<<j))!=0) ){
            col[i]++;
            if(j>0&&((i&(1<<(j-1)))!=0)){
                col[i]--;
            }
            bts[i]++;
        }
    }
}
for(int a=0;a<(1<<m);a++){
    for(int b=0;b<(1<<m);b++){
        for(int j=0;j<m;j++){
            if( ((a&(1<<j))!=0)&&((b&(1<<j))!=0) ){
                sme[a][b]++;
            }
        }
    }
}


for(int i=0;i<=n+1;i++){
    for(int j=0;j<(1<<m)+10;j++){
        dp[i][j]=1e9;
    }
}
dp[0][0]=0;

for(int i=1;i<=n+1;i++){
    for(int mask=0;mask<(1<<m);mask++){
        if(((mask|gr[i])!=gr[i])){continue;}
        for(int mskb=0;mskb<(1<<m);mskb++){
            dp[i][mask]=min(dp[i][mask],dp[i-1][mskb]+bts[mask]-sme[mask][mskb]+col[gr[i]^mask]);
        }
    }
}
cout<<dp[n+1][0]<<endl;




}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 44 ms 15892 KB Output is correct
3 Correct 8 ms 6228 KB Output is correct
4 Correct 18 ms 9304 KB Output is correct
5 Correct 51 ms 16432 KB Output is correct
6 Correct 57 ms 16484 KB Output is correct
7 Correct 56 ms 16288 KB Output is correct
8 Correct 33 ms 15940 KB Output is correct
9 Correct 43 ms 15956 KB Output is correct
10 Correct 684 ms 16592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 8524 KB Output is correct
2 Correct 27 ms 8644 KB Output is correct
3 Correct 25 ms 8632 KB Output is correct
4 Correct 30 ms 8712 KB Output is correct
5 Correct 24 ms 8568 KB Output is correct
6 Correct 28 ms 8612 KB Output is correct
7 Correct 3 ms 1620 KB Output is correct
8 Correct 29 ms 8616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 44 ms 15892 KB Output is correct
3 Correct 8 ms 6228 KB Output is correct
4 Correct 18 ms 9304 KB Output is correct
5 Correct 51 ms 16432 KB Output is correct
6 Correct 57 ms 16484 KB Output is correct
7 Correct 56 ms 16288 KB Output is correct
8 Correct 33 ms 15940 KB Output is correct
9 Correct 43 ms 15956 KB Output is correct
10 Correct 684 ms 16592 KB Output is correct
11 Correct 27 ms 8524 KB Output is correct
12 Correct 27 ms 8644 KB Output is correct
13 Correct 25 ms 8632 KB Output is correct
14 Correct 30 ms 8712 KB Output is correct
15 Correct 24 ms 8568 KB Output is correct
16 Correct 28 ms 8612 KB Output is correct
17 Correct 3 ms 1620 KB Output is correct
18 Correct 29 ms 8616 KB Output is correct
19 Correct 3 ms 4436 KB Output is correct
20 Correct 12 ms 6612 KB Output is correct
21 Correct 34 ms 9388 KB Output is correct
22 Correct 30 ms 16340 KB Output is correct
23 Correct 32 ms 16184 KB Output is correct
24 Correct 40 ms 16236 KB Output is correct
25 Correct 95 ms 16388 KB Output is correct
26 Correct 354 ms 16156 KB Output is correct
27 Correct 748 ms 16112 KB Output is correct
28 Execution timed out 1084 ms 16332 KB Time limit exceeded
29 Halted 0 ms 0 KB -