#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dec(x, y) fixed << setprecision((y)) << (x)
#define xx first
#define yy second
#define srt(v) sort((v).begin(), (v).end())
#define srtr(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define popb pop_back
#define sz(a) (int)(a).size()
#define len(a) (int)(a).length()
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int n;
int s[16][26];
ll dp(int mask) {
for(int i=0; i<n; ++i) {
if(((1<<i)^mask)==0) {
ll duz=0LL;
for(int j=0; j<26; ++j) duz+=s[i][j];
return duz;
}
if((1<<i)&mask) break;
}
int p[26];
for(int i=0; i<26; ++i) p[i]=2000000;
for(int i=0; i<n; ++i) {
if((1<<i)&mask) {
for(int j=0; j<26; ++j) {
p[j]=min(p[j], s[i][j]);
}
}
}
ll duz=0LL;
for(int i=0; i<26; ++i) duz+=(ll)p[i];
ll mini=2000000000000000LL;
for(int sub=(mask-1)&mask; sub>0; sub=(sub-1)&mask) {
if(__builtin_popcount(sub)<__builtin_popcount(mask^sub)) continue;
mini=min(mini, dp(sub)+dp(mask^sub));
}
return mini-duz;
}
int main() {
ios;
cin >> n;
for(int i=0; i<n; ++i) {
string t; cin >> t;
for(int j=0; j<len(t); ++j) {
++s[i][t[j]-'a'];
}
}
cout << dp((1<<n)-1)+1LL;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2069 ms |
204 KB |
Time limit exceeded |
2 |
Execution timed out |
2045 ms |
204 KB |
Time limit exceeded |
3 |
Execution timed out |
2079 ms |
204 KB |
Time limit exceeded |
4 |
Execution timed out |
2078 ms |
204 KB |
Time limit exceeded |
5 |
Execution timed out |
2084 ms |
332 KB |
Time limit exceeded |
6 |
Execution timed out |
2099 ms |
332 KB |
Time limit exceeded |
7 |
Execution timed out |
2096 ms |
332 KB |
Time limit exceeded |
8 |
Execution timed out |
2080 ms |
332 KB |
Time limit exceeded |
9 |
Execution timed out |
2099 ms |
332 KB |
Time limit exceeded |
10 |
Execution timed out |
2094 ms |
332 KB |
Time limit exceeded |