Submission #443155

#TimeUsernameProblemLanguageResultExecution timeMemory
443155penguinhackerVještica (COCI16_vjestica)C++14
160 / 160
91 ms1304 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array int n, dp1[1<<16], dp2[1<<16]; ar<int, 26> cnt[16]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=0; i<n; ++i) { string s; cin >> s; for (char c : s) ++cnt[i][c-'a']; } for (int i=1; i<1<<n; ++i) { for (int j=0; j<26; ++j) { int mn=69696969; for (int k=0; k<n; ++k) if (i&1<<k) mn=min(mn, cnt[k][j]); dp1[i]+=mn; } } for (int i=1; i<1<<n; ++i) { if (__builtin_popcount(i)==1) continue; dp2[i]=69696969; for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1) dp2[i]=min(dp2[i], dp2[j]+dp2[j^i]+dp1[j]+dp1[j^i]-2*dp1[i]); } cout << 1+dp1[(1<<n)-1]+dp2[(1<<n)-1]; return 0; }

Compilation message (stderr)

vjestica.cpp: In function 'int main()':
vjestica.cpp:33:21: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   33 |   for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1)
      |                   ~~^~~~~~~~~~~~~~~~~
vjestica.cpp:33:48: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   33 |   for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1)
      |                                               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...