# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202521 | mahmoudbadawy | Vještica (COCI16_vjestica) | C++17 | 214 ms | 1784 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;
const int N=16;
int mem[(1<<N)];
int cost[(1<<N)];
int co[N][26];
int n;
string arr[N];
int main()
{
cin >> n;
for(int i=0;i<n;i++)
{
cin >> arr[i];
for(int j=0;j<arr[i].size();j++)
co[i][arr[i][j]-'a']++;
}
for(int i=1;i<(1<<n);i++)
{
int cur[26];
memset(cur,'?',sizeof cur);
for(int j=0;j<n;j++)
{
if(i&(1<<j))
{
for(int k=0;k<26;k++)
{
cur[k]=min(cur[k],co[j][k]);
mem[i]+=co[j][k];
}
}
}
for(int j=0;j<26;j++) cost[i]+=cur[j];
}
for(int i=1;i<(1<<n);i++)
{
for(int j=i;j>0;j=(j-1)&i)
{
if(j==i) continue;
mem[i]=min(mem[i],mem[j]+mem[i^j]-cost[i]);
}
}
cout << mem[(1<<n)-1]+1 << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |