Submission #35940

#TimeUsernameProblemLanguageResultExecution timeMemory
35940funcsrVještica (COCI16_vjestica)C++14
160 / 160
153 ms9288 KiB
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> #include <cassert> #include <bitset> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int N; int C[16][26]; int dp[1<<16]; int L[1<<16][26]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; rep(i, N) { string s; cin >> s; for (char c : s) C[i][c-'a']++; } dp[0] = 0; for (int S=1; S<(1<<N); S++) { int popcount = __builtin_popcount(S); rep(j, 26) { int m = INF; rep(i, N) if ((S>>i)&1) m = min(m, C[i][j]); L[S][j] = m; } int c = 0; rep(j, 26) c += L[S][j]; if (popcount == 1) { dp[S] = c; continue; } int m = INF; for (int T=(S-1)&S; T>0; T=(T-1)&S) m = min(m, dp[T] + dp[S^T]); dp[S] = m - c; } cout << dp[(1<<N)-1]+1 << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...