| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 889376 | hieupham1103 | Vještica (COCI16_vjestica) | C++17 | 33 ms | 1372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"bits/stdc++.h"
#define int long long
//#define double long double
#define ii pair <int,int>
#define fi first
#define se second
#define endl '\n'
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
struct dt{
int a[26];
int len = 0;
} a[20];
int co[20][20];
int dp[1 << 20];
signed main(){
//freopen("input.INP", "r", stdin);
//freopen("output.OUT", "w", stdout);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++){
string s;
cin >> s;
for (auto x: s){
a[i].a[x - 'a']++;
}
a[i].len = s.length();
}
// for (int i = 0; i <=n; i++){
// for (int j = 0; j <= 25; j++){
// cout << a[i].a[j] << " ";
// }
// cout << endl;
// }
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
int cnt = 0;
for (int x = 0; x <= 25; x++){
cnt += min(a[i].a[x], a[j].a[x]);
}
co[i][j] = cnt;
}
}
for (int mask = 1; mask < (1 << n); mask++){
for (int i = 0; i < n; i++){
if (mask & (1 << i)){
int laMask = mask ^ (1 << i);
int res = a[i].len;
for (int j = 0; j < n; j++){
if (laMask & (1 << j)){
res = min(res, a[i].len - co[i][j]);
}
}
dp[mask] = max(dp[mask], dp[laMask] + res);
}
}
}
cout << dp[(1 << n) - 1] + 1;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
