| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 453790 | JovanB | Vještica (COCI16_vjestica) | C++17 | 190 ms | 1480 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 16;
int ima[N][26];
int lcp[(1<<N)];
int ch[26];
int dp[(1<<N)];
const int INF = 1000000000;
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n;
cin >> n;
for(int i=0; i<n; i++){
string s;
cin >> s;
for(auto c : s) ima[i][c - 'a']++;
}
for(int mask=1; mask<(1<<n); mask++){
for(int j=0; j<26; j++) ch[j] = INF;
lcp[mask] = 1;
for(int i=0; i<n; i++){
if((1 << i) & mask){
for(int j=0; j<26; j++) ch[j] = min(ch[j], ima[i][j]);
}
}
for(int j=0; j<26; j++) lcp[mask] += ch[j];
}
for(int mask=1; mask<(1<<n); mask++){
dp[mask] = INF;
if(__builtin_popcount(mask) == 1){
dp[mask] = lcp[mask];
continue;
}
for(int submask=mask; submask; submask=(submask-1)&mask){
if(submask == mask) continue;
int ost = mask ^ submask;
dp[mask] = min(dp[mask], dp[submask] + dp[ost] - lcp[mask]);
}
}
cout << dp[(1 << n) - 1] << "\n";
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
