답안 #282295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282295 2020-08-24T09:02:24 Z HynDuf Vještica (COCI16_vjestica) C++14
160 / 160
128 ms 1404 KB
#include <bits/stdc++.h>

#define task "V"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 16;
int n, cnt[N][26], dp[1 << N], common[1 << N];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n;
    rep(i, 0, n - 1)
    {
        string s;
        cin >> s;
        rep(j, 0, SZ(s) - 1) cnt[i][s[j] - 'a']++;
    }
    rep(x, 0, (1 << n) - 1)
    {
        rep(c, 0, 25)
        {
            int mn = 1e9;
            rep(i, 0, n - 1) if (x >> i & 1) mn = min(mn, cnt[i][c]);
            common[x] += mn;
        }
    }
    rep(x, 1, (1 << n) - 1) dp[x] = 1e9;
    rep(i, 0, n - 1) dp[1 << i] = common[1 << i];
    rep(x, 1, (1 << n) - 1)
    {
        for (int subx = x & (x - 1); subx; subx = (subx - 1) & x)
            dp[x] = min(dp[x], dp[subx] + dp[x ^ subx] - common[x]);
    }
    cout << dp[(1 << n) - 1] + 1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 119 ms 912 KB Output is correct
5 Correct 125 ms 888 KB Output is correct
6 Correct 122 ms 1248 KB Output is correct
7 Correct 128 ms 1404 KB Output is correct
8 Correct 122 ms 1400 KB Output is correct
9 Correct 120 ms 1392 KB Output is correct
10 Correct 126 ms 1400 KB Output is correct