Submission #456867

#TimeUsernameProblemLanguageResultExecution timeMemory
456867ntabc05101Vještica (COCI16_vjestica)C++14
160 / 160
114 ms1044 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; #define taskname "" int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int n; cin >> n; int c[n][26]; memset(c, 0, sizeof(c)); string s; for (int i = 0; i < n; i++) { cin >> s; for (auto& _: s) { c[i][_ - 'a']++; } } const int full_bit = 1 << n; int dp[full_bit]; dp[0] = 0; for (int msk = 1; msk < full_bit; msk++) { int n_node = 0; vector<int> _min(26, mod); for (int i = 0; i < n; i++) { if (msk >> i & 1) { for (int j = 0; j < 26; j++) { _min[j] = min(_min[j], c[i][j]); } } } for (int i = 0; i < 26; i++) { n_node += _min[i]; } if ((msk & -msk) == msk) { dp[msk] = n_node; } else { dp[msk] = mod; for (int _msk = (msk - 1) & msk; _msk; _msk = (_msk - 1) & msk) { dp[msk] = min(dp[msk], dp[_msk] + dp[msk ^ _msk] - n_node); } } } //cout << dp[2] << "\n"; cout << dp[full_bit - 1] + 1 << endl; return 0; }

Compilation message (stderr)

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