| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 726433 | YugiHacker | Vještica (COCI16_vjestica) | C++17 | 454 ms | 1552 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
www.youtube.com/YugiHackerChannel
oj.vnoi.info/user/YugiHackerKhongCopCode
*/
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn
#define bit(mask,i) ((mask>>i)&1)
using namespace std;
int n;
string s[16];
int cnt[16][26];
int f[1 << 16];
int val(int mask)
{
vector <int> mi(26, 1e9);
f0 (i, n) if (bit(mask, i))
f0 (j, 26) mi[j] = min(mi[j], cnt[i][j]);
return accumulate(mi.begin(), mi.end(), 0);
}
int calc(int mask)
{
int &ans = f[mask];
if (ans != -1) return ans;
int common = val(mask);
if (__builtin_popcount(mask) == 1) return common;
ans = 1e9;
for (int i=(mask - 1) & mask; i; i = (i-1) & mask)
ans = min(ans, calc(i) + calc(mask ^ i) - common);
return ans;
}
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
f0 (i, n)
{
cin >> s[i];
for (char c:s[i]) cnt[i][c-'a']++;
}
memset(f, -1, sizeof f);
cout << calc((1 << n) - 1) + 1;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
