# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
167555 | combi1k1 | Vještica (COCI16_vjestica) | C++14 | 371 ms | 1656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
vector<int> s[16];
int A[1 << 16];
int f[1 << 16];
int work(int m) {
if (m == 0) return 0;
if (f[m] < inf) return f[m];
if (__builtin_popcount(m) == 1)
return f[m] = A[m];
for(int x = m ; x ; x = (x - 1) & m) if (x ^ m)
f[m] = min(f[m],work(x) + work(m ^ x) - A[m]);
return f[m];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for(int i = 0 ; i < n ; ++i) {
s[i].resize(26);
string t; cin >> t;
for(char c : t)
s[i][c - 'a']++;
}
for(int i = 1 ; i < (1 << n) ; ++i) {
vector<int> c(26,1e6);
for(int j = 0 ; j < n ; ++j) if (i >> j & 1)
for(int k = 0 ; k < 26 ; ++k) c[k] = min(c[k],s[j][k]);
for(int x : c)
A[i] += x;
}
memset(f,0x3f3f3f3f,sizeof f);
cout << work((1 << n) - 1) + 1 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |