답안 #482390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482390 2021-10-24T09:33:39 Z MilosMilutinovic Vještica (COCI16_vjestica) C++14
160 / 160
96 ms 960 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=17;
int n,cc[N][26],len[N],dp[1<<N];
char s[N];
int mn[26];

int main() {
    scanf("%d",&n);
    rep(i,0,n) {
        scanf("%s",s);
        len[i]=strlen(s);
        rep(j,0,len[i]) cc[i][s[j]-'a']++;
    }
    rep(msk,1,(1<<n)){
        if (__builtin_popcount(msk)==1) {
            rep(j,0,n) if(msk&(1<<j)) dp[msk]=len[j];
            continue;
        }
        rep(j,0,26) mn[j]=1e9;
        rep(j,0,n) if(msk&(1<<j)) rep(k,0,26) mn[k]=min(mn[k],cc[j][k]);
        int tot=0; rep(j,0,26) tot+=mn[j];
        dp[msk]=1e9;
        for (int sub=(msk&(msk-1));sub>0;sub=(msk&(sub-1))) dp[msk]=min(dp[msk],dp[sub]+dp[msk^sub]-tot);
    }
    printf("%d",dp[(1<<n)-1]+1);
}

Compilation message

vjestica.cpp: In function 'int main()':
vjestica.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
vjestica.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%s",s);
      |         ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 82 ms 520 KB Output is correct
5 Correct 82 ms 552 KB Output is correct
6 Correct 84 ms 716 KB Output is correct
7 Correct 96 ms 908 KB Output is correct
8 Correct 85 ms 960 KB Output is correct
9 Correct 86 ms 836 KB Output is correct
10 Correct 85 ms 836 KB Output is correct