Submission #482390

#TimeUsernameProblemLanguageResultExecution timeMemory
482390MilosMilutinovicVještica (COCI16_vjestica)C++14
160 / 160
96 ms960 KiB
#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 (stderr)

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);
      |         ~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...