# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
623109 | inksamurai | Vještica (COCI16_vjestica) | C++17 | 112 ms | 1108 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,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3SgiE60 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
const int inf=1e9;
signed main(){
_3SgiE60;
int n;
cin>>n;
vec(vi) a(n,vi(26));
vi dp((1<<n),inf);
rep(i,n){
string s;
cin>>s;
dp[(1<<i)]=sz(s);
rep(j,sz(s)){
a[i][s[j]-'a']+=1;
}
}
rep(msk,(1<<n)){
vi rbe(26,1e9);
int sun=0;
rep(ch,26){
rep(i,n){
if(msk>>i&1){
rbe[ch]=min(rbe[ch],a[i][ch]);
}
}
sun+=rbe[ch];
}
for(int nmsk=msk;nmsk;nmsk=(nmsk-1)&msk){
int now=dp[nmsk]+dp[msk^nmsk];
// if(msk==3) print(msk,nmsk);
now-=sun;
dp[msk]=min(dp[msk],now);
}
}
// print(dp[3]);
print(dp[(1<<n)-1]+1);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |