# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1128296 | ntdaccode | Vještica (COCI16_vjestica) | C++20 | 62 ms | 1352 KiB |
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;
const int M = 1e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
int n, cnt[20][30];
string s[20];
int f[1 << 16], g[1 << 16];
int tmp[30];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("1.inp","r")) {
freopen("1.inp","r",stdin);
freopen("1.out","w",stdout);
}
#define task ""
if(fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n;
for(int i = 1;i <= n; i++) cin >> s[i];
for(int i = 1;i <= n; i++) {
int m = s[i].size();
for(int j = 0;j < s[i].size(); j++) cnt[i][s[i][j] - 'a']++;
}
for(int mask = 1;mask < (1 << n); mask++) {
for(int i = 0;i <= 25; i++) tmp[i] = 1e9;
for(int i = 1;i <= n; i++) {
if((mask >> i - 1) & 1) {
for(int digit = 0;digit <= 25; digit++) {
tmp[digit] = min(tmp[digit], cnt[i][digit]);
}
}
}
int k = __builtin_popcount(mask);
for(int digit = 0;digit <= 25; digit++) {
g[mask] += tmp[digit];
}
//cout << mask << " " << g[mask] << " " << k << "\n";
}
memset(f, 61, sizeof(f));
for(int i = 1;i <= n; i++) {
f[1 << i - 1] = s[i].size();
}
for(int mask = 1;mask < (1 << n); mask++) {
if(__builtin_popcount(mask) == 1) continue;
for(int submask = mask; submask; submask = (submask - 1) & mask) {
f[mask] = min(f[mask], f[submask] + f[submask ^ mask] - g[mask]);
}
//cout << mask << " " << f[mask] << "\n";
}
cout << f[(1<<n) - 1] + 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |