Submission #889376

#TimeUsernameProblemLanguageResultExecution timeMemory
889376hieupham1103Vještica (COCI16_vjestica)C++17
0 / 160
33 ms1372 KiB
#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 (stderr)

vjestica.cpp: In function 'int main()':
vjestica.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
vjestica.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...