Submission #1093949

#TimeUsernameProblemLanguageResultExecution timeMemory
1093949m5588ohammedVještica (COCI16_vjestica)C++14
0 / 160
2076 ms17752 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long int common[(1<<16)+1],fre[(1<<16)+1][30],vis[(1<<16)+1],fre2[(1<<16)+1]; int n; int count(int x){ int cnt=0; for(int i=0;i<=16;i++) if((bool)((1<<i)&x)!=0) cnt++; return cnt; } void build(int x){ if(vis[x]==1||count(x)==1) return; vis[x]=1; int num=x,j=0; for(int bt=0;bt<=16;bt++){ if((bool)((1<<bt)&x)!=0){ num^=(1<<bt); j=bt; break; } } build(num); int sum=0; for(int i=0;i<30;i++){ fre[x][i]=min(fre[(1<<j)][i],fre[num][i]); sum+=fre[x][i]; } common[x]=sum; return; } int solve(int x); int rec(int x,int num,int i){ if(i==n){ if(x!=num&&num!=0) return solve(num)+solve(x^num)-common[x]*2+common[num]+common[x^num]; else return 1e15; } if((bool)(x&(1<<i))==0) return rec(x,num,i+1); else return min(rec(x,num,i+1),rec(x,(int)(num|(1<<i)),i+1)); } int solve(int x){ if(count(x)==1) return 0; return rec(x,0,0); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=0;i<n;i++){ string s; cin>>s; for(int j=0;j<s.size();j++) fre[(1<<i)][s[j]-97]++; common[(1<<i)]=s.size(); } for(int i=1;i<=(1<<n)-1;i++) build(i); //cout<<(1<<n)-1<<" "<<common[6]<<endl; cout<<solve((1<<n)-1)+common[(1<<n)-1]+1<<endl; return 0; }

Compilation message (stderr)

vjestica.cpp: In function 'int main()':
vjestica.cpp:54:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int j=0;j<s.size();j++) fre[(1<<i)][s[j]-97]++;
      |                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...