답안 #107630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107630 2019-04-25T10:40:53 Z Milki Vještica (COCI16_vjestica) C++14
0 / 160
32 ms 3372 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 17, MAX = 1 << 17, ABC = 27, inf = 1e9;

int n;
int dp[MAX], let[MAXN][ABC];
bool bio[MAX];
vector <int> visited, tmp;

int get(int mask){
  int tmp[26];
  REP(i, 26)
    tmp[i] = inf;
  REP(i, n){
    if( (mask & (1 << i)) == 0) continue;
    REP(j, 26)
      tmp[j] = min(tmp[j], let[i][j]);
  }
  int ret = 0;
  REP(i, 26)
    ret += tmp[i];
  return ret;
}

int rek(int mask){
  if(dp[mask]) return dp[mask];
  if(__builtin_popcount(mask) == 1) return dp[mask] = get(mask);
  tmp.clear();
  visited.clear();

  int sub = get(mask), gen = 0;
  REP(i, n){
    if((1 << i) & mask){
      tmp.pb(i);
      gen |= (1 << i);
    }
  }
  int ret = inf;

  for (int newMask = mask - 1; newMask > 0; newMask = (newMask - 1) & newMask)
    ret = min(ret, rek(newMask) + rek(newMask ^ mask) - sub);
  return dp[mask] = ret;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);

  cin >> n;
  REP(i, n){
    string s; cin >> s;
    REP(j, sz(s))
      let[i][s[j] - 'a'] ++;
  }
  cout << rek((1 << n) - 1) + 1;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Incorrect 29 ms 3192 KB Output isn't correct
5 Incorrect 32 ms 3192 KB Output isn't correct
6 Incorrect 29 ms 3320 KB Output isn't correct
7 Incorrect 30 ms 3316 KB Output isn't correct
8 Incorrect 30 ms 3328 KB Output isn't correct
9 Incorrect 31 ms 3312 KB Output isn't correct
10 Incorrect 31 ms 3372 KB Output isn't correct