Submission #443155

# Submission time Handle Problem Language Result Execution time Memory
443155 2021-07-09T21:16:47 Z penguinhacker Vještica (COCI16_vjestica) C++14
160 / 160
91 ms 1304 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

int n, dp1[1<<16], dp2[1<<16];
ar<int, 26> cnt[16];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i) {
		string s;
		cin >> s;
		for (char c : s)
			++cnt[i][c-'a'];
	}
	for (int i=1; i<1<<n; ++i) {
		for (int j=0; j<26; ++j) {
			int mn=69696969;
			for (int k=0; k<n; ++k)
				if (i&1<<k)
					mn=min(mn, cnt[k][j]);
			dp1[i]+=mn;
		}
	}
	for (int i=1; i<1<<n; ++i) {
		if (__builtin_popcount(i)==1)
			continue;
		dp2[i]=69696969;
		for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1)
			dp2[i]=min(dp2[i], dp2[j]+dp2[j^i]+dp1[j]+dp1[j^i]-2*dp1[i]);
	}
	cout << 1+dp1[(1<<n)-1]+dp2[(1<<n)-1];
	return 0;
}

Compilation message

vjestica.cpp: In function 'int main()':
vjestica.cpp:33:21: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   33 |   for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1)
      |                   ~~^~~~~~~~~~~~~~~~~
vjestica.cpp:33:48: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   33 |   for (int j=i^1<<31-__builtin_clz(i); j; j=i&j-1)
      |                                               ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 86 ms 812 KB Output is correct
5 Correct 87 ms 892 KB Output is correct
6 Correct 91 ms 1140 KB Output is correct
7 Correct 89 ms 1216 KB Output is correct
8 Correct 89 ms 1272 KB Output is correct
9 Correct 88 ms 1296 KB Output is correct
10 Correct 89 ms 1304 KB Output is correct