# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
671036 | Do_you_copy | Vještica (COCI16_vjestica) | C++17 | 171 ms | 1640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
I find it wholesome to be alone the greater part of the time.
To be in company, even with the best, is soon wearisome and dissipating.
I love to be alone.
I never found the companion that was so companionable as solitude.
*/
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 1;
//const int Mod = 1e9 + 7;
//const int inf =
int n;
int cnt[30][30];
int f[1 << 17];
int dp[1 << 17];
void Init(){
cin >> n;
memset(dp, 0x3f, sizeof(dp));
for (int i = 0; i < n; ++i){
string s; cin >> s;
for (char c: s){
++cnt[i][c - 'a'];
}
}
for (int i = 1; i < 1 << n; ++i){
int b[26]; memset(b, 0x3f, sizeof(b));
for (int j = 0; j < n; ++j){
if ((i & (1 << j)) == 0) continue;
for (int k = 0; k < 26; ++k){
b[k] = min(b[k], cnt[j][k]);
}
}
for (int j = 0; j < 26; ++j) f[i] += b[j];
}
for (int i = 1; i < 1 << n; ++i){
if (__builtin_popcount(i) == 1){
dp[i] = f[i];
continue;
}
for (int j = i; j; j = (j - 1) & i){
int k = i ^ j;
if (!k) continue;
dp[i] = min(dp[i], dp[j] + dp[k] - f[i]);
}
}
cout << dp[(1 << n) - 1] + 1;
}
#define debug
#define taskname "test"
signed main(){
faster
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
int tt = 1;
//cin >> tt;
while (tt--){
Init();
}
if (fopen("timeout.txt", "r")){
ofstream timeout("timeout.txt");
timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
timeout.close();
#ifndef debug
cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
#endif // debug
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |