# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
531981 | colazcy | Vještica (COCI16_vjestica) | C++17 | 93 ms | 1864 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.
#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <numeric>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_lIM = lim,REPN = 1;REPN <= REPN_lIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 1e6 + 2333,inf = 0x3f3f3f3f;
int n,cnt[16][26],tmp[26],len[16],f[1 << 16];
char buf[maxn],*str[16],*now = buf;
int main(){
// std::freopen("vjestica.in","r",stdin);
// std::freopen("mag.out","w",stdout);
std::scanf("%d",&n);
rep(i,0,n - 1){
std::scanf("%s",str[i] = now);
len[i] = std::strlen(str[i]);
now += len[i] + 1;
}
rep(i,0,n - 1)debug("%s\n",str[i]);
rep(i,0,n - 1)
rep(j,0,len[i] - 1)
cnt[i][str[i][j] - 'a']++;
let full = (1 << n) - 1;
std::memset(f,0x3f,sizeof(f));
f[0] = 0;
rep(s,1,full){
for(int t = s;t;t = (t - 1) & s)
f[s] = std::min
(f[s],f[t] + f[s ^ t]);
std::fill_n(tmp,26,inf);
rep(i,0,n - 1)
if((s >> i) & 1)
rep(j,0,25)
tmp[j] = std::min(tmp[j],cnt[i][j]);
let sum = std::accumulate(tmp,tmp + 26,0);
f[s] -= sum;
int slen = 0;
rep(i,0,n - 1)
if((s >> i) & 1)slen += len[i];
f[s] = std::min(f[s],slen - sum * (__builtin_popcount(s) - 1));
}
std::printf("%d\n",1 + f[full]);
std::fclose(stdin);
std::fclose(stdout);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |