# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
889376 | 2023-12-19T14:45:36 Z | hieupham1103 | Vještica (COCI16_vjestica) | C++17 | 33 ms | 1372 KB |
#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; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Incorrect | 1 ms | 348 KB | Output isn't correct |
4 | Incorrect | 31 ms | 860 KB | Output isn't correct |
5 | Incorrect | 31 ms | 1052 KB | Output isn't correct |
6 | Incorrect | 31 ms | 1112 KB | Output isn't correct |
7 | Incorrect | 32 ms | 1368 KB | Output isn't correct |
8 | Incorrect | 32 ms | 1372 KB | Output isn't correct |
9 | Incorrect | 33 ms | 1300 KB | Output isn't correct |
10 | Incorrect | 32 ms | 1372 KB | Output isn't correct |