# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482390 | MilosMilutinovic | Vještica (COCI16_vjestica) | C++14 | 96 ms | 960 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 rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=17;
int n,cc[N][26],len[N],dp[1<<N];
char s[N];
int mn[26];
int main() {
scanf("%d",&n);
rep(i,0,n) {
scanf("%s",s);
len[i]=strlen(s);
rep(j,0,len[i]) cc[i][s[j]-'a']++;
}
rep(msk,1,(1<<n)){
if (__builtin_popcount(msk)==1) {
rep(j,0,n) if(msk&(1<<j)) dp[msk]=len[j];
continue;
}
rep(j,0,26) mn[j]=1e9;
rep(j,0,n) if(msk&(1<<j)) rep(k,0,26) mn[k]=min(mn[k],cc[j][k]);
int tot=0; rep(j,0,26) tot+=mn[j];
dp[msk]=1e9;
for (int sub=(msk&(msk-1));sub>0;sub=(msk&(sub-1))) dp[msk]=min(dp[msk],dp[sub]+dp[msk^sub]-tot);
}
printf("%d",dp[(1<<n)-1]+1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |