# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
726433 | YugiHacker | Vještica (COCI16_vjestica) | C++17 | 454 ms | 1552 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.
/*
www.youtube.com/YugiHackerChannel
oj.vnoi.info/user/YugiHackerKhongCopCode
*/
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn
#define bit(mask,i) ((mask>>i)&1)
using namespace std;
int n;
string s[16];
int cnt[16][26];
int f[1 << 16];
int val(int mask)
{
vector <int> mi(26, 1e9);
f0 (i, n) if (bit(mask, i))
f0 (j, 26) mi[j] = min(mi[j], cnt[i][j]);
return accumulate(mi.begin(), mi.end(), 0);
}
int calc(int mask)
{
int &ans = f[mask];
if (ans != -1) return ans;
int common = val(mask);
if (__builtin_popcount(mask) == 1) return common;
ans = 1e9;
for (int i=(mask - 1) & mask; i; i = (i-1) & mask)
ans = min(ans, calc(i) + calc(mask ^ i) - common);
return ans;
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
f0 (i, n)
{
cin >> s[i];
for (char c:s[i]) cnt[i][c-'a']++;
}
memset(f, -1, sizeof f);
cout << calc((1 << n) - 1) + 1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |