# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249663 | 2020-07-15T14:08:14 Z | Mercenary | Vještica (COCI16_vjestica) | C++14 | 2000 ms | 1152 KB |
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 5e5 + 5; const int logn = log2(maxn) + 1; int a[16][26]; int n; int dp[1 << 16]; int get(int s){ if(s == 0)return 0; int res = 0; for(int i = 0 ; i < 26 ; ++i){ int tmp = 1e6; for(int j = 0 ; j < n ; ++j){ if(s & (1 << j))tmp = min(tmp , a[j][i]); } res += tmp; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n; for(int i = 0 ; i < n ; ++i){ string s;cin >> s; for(auto & c : s)a[i][c - 'a']++; } memset(dp,123,sizeof dp); for(int i = 0 ; i < n ; ++i)dp[1 << i] = 0; for(int i = 0 ; i < (1 << n) ; ++i){ int tmp = get(i); for(int j = (i - 1) & i ; j > 0 ; j = ((j - 1) & i)){ dp[i] = min(dp[i] , dp[j] + dp[i ^ j] + get(j) + get(i ^ j) - 2 * get(i)); } } cout << 1 + get((1 << n) - 1) + dp[(1 << n) - 1]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 61 ms | 640 KB | Output is correct |
2 | Correct | 64 ms | 644 KB | Output is correct |
3 | Correct | 62 ms | 640 KB | Output is correct |
4 | Execution timed out | 2090 ms | 640 KB | Time limit exceeded |
5 | Execution timed out | 2087 ms | 640 KB | Time limit exceeded |
6 | Execution timed out | 2080 ms | 896 KB | Time limit exceeded |
7 | Execution timed out | 2086 ms | 1140 KB | Time limit exceeded |
8 | Execution timed out | 2081 ms | 1152 KB | Time limit exceeded |
9 | Execution timed out | 2064 ms | 1144 KB | Time limit exceeded |
10 | Execution timed out | 2090 ms | 1152 KB | Time limit exceeded |