Submission #726433

#TimeUsernameProblemLanguageResultExecution timeMemory
726433YugiHackerVještica (COCI16_vjestica)C++17
160 / 160
454 ms1552 KiB
/* www.youtube.com/YugiHackerChannel oj.vnoi.info/user/YugiHackerKhongCopCode */ #include<bits/stdc++.h> #define el cout<<"\n" #define f0(i,n) for(int i=0;i<n;++i) #define f1(i,n) for(int i=1;i<=n;++i) #define maxn #define bit(mask,i) ((mask>>i)&1) using namespace std; int n; string s[16]; int cnt[16][26]; int f[1 << 16]; int val(int mask) { vector <int> mi(26, 1e9); f0 (i, n) if (bit(mask, i)) f0 (j, 26) mi[j] = min(mi[j], cnt[i][j]); return accumulate(mi.begin(), mi.end(), 0); } int calc(int mask) { int &ans = f[mask]; if (ans != -1) return ans; int common = val(mask); if (__builtin_popcount(mask) == 1) return common; ans = 1e9; for (int i=(mask - 1) & mask; i; i = (i-1) & mask) ans = min(ans, calc(i) + calc(mask ^ i) - common); return ans; } main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; f0 (i, n) { cin >> s[i]; for (char c:s[i]) cnt[i][c-'a']++; } memset(f, -1, sizeof f); cout << calc((1 << n) - 1) + 1; }

Compilation message (stderr)

vjestica.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...