Submission #299010

#TimeUsernameProblemLanguageResultExecution timeMemory
299010mat_vVještica (COCI16_vjestica)C++14
160 / 160
241 ms832 KiB
#include <bits/stdc++.h> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define xx first #define yy second #define pii pair<int,int> using namespace std; int n; int freq[20][30]; int dp[67000]; bool bio[67000]; int mini[30]; int resi(int mask){ if(bio[mask])return dp[mask]; bio[mask] = 1; int tr = 0; ff(i,0,25)mini[i] = 1e9; int kol = 0; ff(i,0,n - 1){ if((1<<i)&mask){ kol++; ff(j,0,26){ mini[j] = min(mini[j], freq[i][j]); } } } ff(j,0,26){ tr += mini[j]; } // cout << mask << " " << tr << "\n"; if(kol == 1)return dp[mask] = tr; int p1 = 1e9; for(int submask = mask; submask; submask = (submask - 1) & mask){ if(submask == mask)continue; p1 = min(p1, resi(submask) + resi(mask^submask)); } return dp[mask] = -tr + p1; } int main() { ios_base::sync_with_stdio(false); cin >> n; ff(i,0,n - 1){ string x; cin >> x; int m = x.length(); ff(j,0,m - 1)freq[i][x[j] - 'a']++; } cout << resi((1<<n) - 1) + 1; return 0; }

Compilation message (stderr)

vjestica.cpp: In function 'int resi(int)':
vjestica.cpp:2:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
vjestica.cpp:21:5: note: in expansion of macro 'ff'
   21 |     ff(i,0,25)mini[i] = 1e9;
      |     ^~
vjestica.cpp:2:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
vjestica.cpp:23:5: note: in expansion of macro 'ff'
   23 |     ff(i,0,n - 1){
      |     ^~
vjestica.cpp:2:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
vjestica.cpp:26:13: note: in expansion of macro 'ff'
   26 |             ff(j,0,26){
      |             ^~
vjestica.cpp:2:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
vjestica.cpp:31:5: note: in expansion of macro 'ff'
   31 |     ff(j,0,26){
      |     ^~
vjestica.cpp: In function 'int main()':
vjestica.cpp:2:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
vjestica.cpp:48:5: note: in expansion of macro 'ff'
   48 |     ff(i,0,n - 1){
      |     ^~
vjestica.cpp:2:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
vjestica.cpp:52:9: note: in expansion of macro 'ff'
   52 |         ff(j,0,m - 1)freq[i][x[j] - 'a']++;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...