제출 #877182

#제출 시각아이디문제언어결과실행 시간메모리
877182noiaintVještica (COCI16_vjestica)C++17
160 / 160
104 ms2352 KiB
#include <bits/stdc++.h> #define int long long using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif #define file "" #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define bit(x) (1LL << (x)) #define getbit(x, i) (((x) >> (i)) & 1) #define popcount __builtin_popcountll mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rd() % (r - l + 1); } const int N = 16; const int mod = (int)1e9 + 7; // 998244353; const int lg = 25; // lg + 1 const int oo = 1e9; const long long ooo = 1e18; template<class X, class Y> bool mini(X &a, Y b) { return a > b ? (a = b, true) : false; } template<class X, class Y> bool maxi(X &a, Y b) { return a < b ? (a = b, true) : false; } void add(int &a, int b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } int n; int f[1 << 16]; int mn[1 << 16]; int cnt[16][26]; void process() { memset(f, 0x3f3f3f, sizeof f); cin >> n; for (int i = 0; i < n; ++i) { string s; cin >> s; for (char c : s) cnt[i][c - 'a']++; f[bit(i)] = (int) s.size(); } for (int mask = 1; mask < bit(n); ++mask) { for (int c = 0; c < 26; ++c) { int cur = oo; for (int i = 0; i < n; ++i) { if (getbit(mask, i)) mini(cur, cnt[i][c]); } mn[mask] += cur; } } for (int x = 0; x < bit(n); ++x) { int s = (bit(n) - 1) ^ x; for (int y = s; y; y = (y - 1) & s) { mini(f[x | y], f[x] + f[y] - mn[x | y]); } } cout << f[bit(n) - 1] + 1; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); int tc = 1; // cin >> tc; while (tc--) { process(); } return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...