Submission #202521

#TimeUsernameProblemLanguageResultExecution timeMemory
202521mahmoudbadawyVještica (COCI16_vjestica)C++17
160 / 160
214 ms1784 KiB
#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)

vjestica.cpp: In function 'int main()':
vjestica.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<arr[i].size();j++)
               ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...