Submission #1128296

#TimeUsernameProblemLanguageResultExecution timeMemory
1128296ntdaccodeVještica (COCI16_vjestica)C++20
160 / 160
62 ms1352 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define pb push_back using namespace std; typedef pair<int,int> ii; typedef tuple<int,int,int> tp; const int M = 1e6 + 10; const int N = 1e3 + 10; const int mod = 1e9 + 7; int n, cnt[20][30]; string s[20]; int f[1 << 16], g[1 << 16]; int tmp[30]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n; for(int i = 1;i <= n; i++) cin >> s[i]; for(int i = 1;i <= n; i++) { int m = s[i].size(); for(int j = 0;j < s[i].size(); j++) cnt[i][s[i][j] - 'a']++; } for(int mask = 1;mask < (1 << n); mask++) { for(int i = 0;i <= 25; i++) tmp[i] = 1e9; for(int i = 1;i <= n; i++) { if((mask >> i - 1) & 1) { for(int digit = 0;digit <= 25; digit++) { tmp[digit] = min(tmp[digit], cnt[i][digit]); } } } int k = __builtin_popcount(mask); for(int digit = 0;digit <= 25; digit++) { g[mask] += tmp[digit]; } //cout << mask << " " << g[mask] << " " << k << "\n"; } memset(f, 61, sizeof(f)); for(int i = 1;i <= n; i++) { f[1 << i - 1] = s[i].size(); } for(int mask = 1;mask < (1 << n); mask++) { if(__builtin_popcount(mask) == 1) continue; for(int submask = mask; submask; submask = (submask - 1) & mask) { f[mask] = min(f[mask], f[submask] + f[submask ^ mask] - g[mask]); } //cout << mask << " " << f[mask] << "\n"; } cout << f[(1<<n) - 1] + 1; }

Compilation message (stderr)

vjestica.cpp: In function 'int32_t main()':
vjestica.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
vjestica.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
vjestica.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
vjestica.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...