# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35940 | funcsr | Vještica (COCI16_vjestica) | C++14 | 153 ms | 9288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |