답안 #242301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242301 2020-06-27T08:33:39 Z kshitij_sodani Vještica (COCI16_vjestica) C++17
160 / 160
187 ms 1144 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'

int n;
int freq[16][26];
int dp[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		string t;
		cin>>t;
		for(int j=0;j<t.size();j++){
			freq[i][t[j]-'a']++;
		}
		dp[(1<<i)]=t.size();
	}
	for(int i=1;i<(1<<n);i++){
		if(__builtin_popcount(i)==1){
			continue;
		}
		dp[i]=1e6;
		int co[26];
		for(int j=0;j<26;j++){
			co[j]=1000000;
		}
		for(int j=0;j<n;j++){
			if((1<<j)&i){
				for(int k=0;k<26;k++){
					co[k]=min(co[k],freq[j][k]);
				}
			}
		}
		int su=0;
		for(int j=0;j<26;j++){
			su+=co[j];
		}
		for(int j=i;j>0;j=(j-1)&i){
			if(j==i){
				continue;
			}
			dp[i]=min(dp[i],dp[j]+dp[i-j]-su);
		}
	}
	cout<<dp[(1<<n)-1]+1<<endl;






	
	return 0;
}

Compilation message

vjestica.cpp: In function 'int main()':
vjestica.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<t.size();j++){
               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 184 ms 632 KB Output is correct
5 Correct 184 ms 632 KB Output is correct
6 Correct 184 ms 892 KB Output is correct
7 Correct 186 ms 1076 KB Output is correct
8 Correct 187 ms 1144 KB Output is correct
9 Correct 186 ms 1132 KB Output is correct
10 Correct 186 ms 1112 KB Output is correct