# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
167649 | DrumpfTheGodEmperor | Vještica (COCI16_vjestica) | C++14 | 129 ms | 1912 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 20, MASK = (1 << 16) + 5;
string s[N];
int n, cnt[N][26], ans[MASK], lcp[MASK];
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
fw (i, 0, n) {
cin >> s[i];
fa (j, s[i]) cnt[i][j - 'a']++;
}
fw (i, 1, (1 << n)) {
fw (j, 0, 26) {
int mn = inf;
fw (k, 0, n) if (i & (1 << k)) mn = min(mn, cnt[k][j]);
lcp[i] += mn;
}
}
ans[0] = inf;
fw (i, 1, (1 << n)) {
int totalLen = 0;
fw (j, 0, n) if (i & (1 << j)) totalLen += s[j].length();
totalLen -= (bp(i) - 1) * lcp[i];
ans[i] = totalLen;
for (int submask = i; submask; submask = (submask - 1) & i) {
ans[i] = min(ans[i], ans[submask] + ans[i ^ submask] - lcp[i]);
}
// cout << "ans[" << i << "] = " << ans[i] << "\n";
}
cout << ans[(1 << n) - 1] + 1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |