# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
521053 | Vladth11 | Vještica (COCI16_vjestica) | C++14 | 2073 ms | 1096 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
const int NMAX = 16;
const int VMAX = 21;
const int INF = (1LL << 60);
const int MOD = 1000000007;
const int BLOCK = 318;
const int base = 31;
const int nr_of_bits = 21;
int dp[(1 << NMAX)];
int cnt[NMAX][26];
int solve(int mask) {
vector <int> v;
for(int i = 0; i < NMAX; i++) {
if(mask & (1 << i))
v.push_back(i);
}
if(v.size() == 1) {
int c = 0;
for(int j = 0; j < 26; j++) {
c += cnt[v.back()][j];
//debug(cnt[v.back()][j]);
}
return dp[mask] = c;
}
int cate = 0;
vector <int> copie;
for(int j = 0; j < 26; j++) {
int minim = 2e9;
for(auto x : v) {
minim = min(minim, cnt[x][j]);
}
cate += minim;
for(auto x : v) {
cnt[x][j] -= minim;
}
copie.push_back(minim);
}
int minim = 2e9;
for(int submask = (mask - 1) & mask; submask > 0; submask = ((submask - 1) & mask)) {
minim = min(minim, cate + solve(submask) + solve(submask ^ mask));
}
for(int j = 0; j < 26; j++) {
for(auto x : v) {
cnt[x][j] += copie[j];
}
}
return dp[mask] = minim;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
for(auto x : s){
cnt[i][x - 'a']++;
}
}
for(int i = 0; i < (1 << n); i++)
dp[i] = -1;
cout << solve((1 << n) - 1) + 1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |