# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
304959 | 2020-09-22T09:32:12 Z | BeanZ | Vještica (COCI16_vjestica) | C++14 | 1259 ms | 1272 KB |
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll int #define endl '\n' const int N = 1e5 + 5; ll cnt[20][26], dp[(1 << 16) + 1]; ll n; ll cal(ll mask){ ll ans = 0; for (int j = 0; j < 26; j++){ ll res = 1e9; for (int i = 0; i < n; i++){ if (mask & (1 << i)){ res = min(res, cnt[i][j]); } } ans = ans + res; } return ans; } ll DP(ll mask){ if (__builtin_popcount(mask) == 1) return cal(mask); if (dp[mask] != -1) return dp[mask]; ll prev = cal(mask); dp[mask] = 1e9; for (int i = (mask - 1) & mask; i; i = (i - 1) & mask){ dp[mask] = min(dp[mask], DP(i) + DP(mask ^ i) - prev); } return dp[mask]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } cin >> n; for (int i = 0; i < n; i++){ string s; cin >> s; for (int j = 0; j < s.length(); j++){ cnt[i][s[j] - 'a']++; } } memset(dp, -1, sizeof(dp)); cout << DP((1 << n) - 1) + 1; } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 640 KB | Output is correct |
2 | Correct | 6 ms | 640 KB | Output is correct |
3 | Correct | 6 ms | 640 KB | Output is correct |
4 | Correct | 1237 ms | 760 KB | Output is correct |
5 | Correct | 1245 ms | 640 KB | Output is correct |
6 | Correct | 1242 ms | 896 KB | Output is correct |
7 | Correct | 1247 ms | 1140 KB | Output is correct |
8 | Correct | 1246 ms | 1272 KB | Output is correct |
9 | Correct | 1259 ms | 1268 KB | Output is correct |
10 | Correct | 1254 ms | 1152 KB | Output is correct |