# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443155 | penguinhacker | Vještica (COCI16_vjestica) | C++14 | 91 ms | 1304 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
int n, dp1[1<<16], dp2[1<<16];
ar<int, 26> cnt[16];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i) {
string s;
cin >> s;
for (char c : s)
++cnt[i][c-'a'];
}
for (int i=1; i<1<<n; ++i) {
for (int j=0; j<26; ++j) {
int mn=69696969;
for (int k=0; k<n; ++k)
if (i&1<<k)
mn=min(mn, cnt[k][j]);
dp1[i]+=mn;
}
}
for (int i=1; i<1<<n; ++i) {
if (__builtin_popcount(i)==1)
continue;
dp2[i]=69696969;
for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1)
dp2[i]=min(dp2[i], dp2[j]+dp2[j^i]+dp1[j]+dp1[j^i]-2*dp1[i]);
}
cout << 1+dp1[(1<<n)-1]+dp2[(1<<n)-1];
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |