Submission #202521

# Submission time Handle Problem Language Result Execution time Memory
202521 2020-02-16T22:13:20 Z mahmoudbadawy Vještica (COCI16_vjestica) C++17
160 / 160
214 ms 1784 KB
#include <bits/stdc++.h>

using namespace std;

const int N=16;

int mem[(1<<N)];
int cost[(1<<N)];
int co[N][26];
int n;
string arr[N];

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> arr[i];
		for(int j=0;j<arr[i].size();j++)
			co[i][arr[i][j]-'a']++;
	}
	for(int i=1;i<(1<<n);i++)
	{
		int cur[26];
		memset(cur,'?',sizeof cur);
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				for(int k=0;k<26;k++)
				{
					cur[k]=min(cur[k],co[j][k]);
					mem[i]+=co[j][k];
				}
			}
		}
		for(int j=0;j<26;j++) cost[i]+=cur[j];
	}
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=i;j>0;j=(j-1)&i)
		{
			if(j==i) continue;
			mem[i]=min(mem[i],mem[j]+mem[i^j]-cost[i]);
		}
	}
	cout << mem[(1<<n)-1]+1 << endl;
}

Compilation message

vjestica.cpp: In function 'int main()':
vjestica.cpp:19:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<arr[i].size();j++)
               ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 190 ms 760 KB Output is correct
5 Correct 195 ms 1016 KB Output is correct
6 Correct 206 ms 1528 KB Output is correct
7 Correct 210 ms 1660 KB Output is correct
8 Correct 214 ms 1784 KB Output is correct
9 Correct 212 ms 1784 KB Output is correct
10 Correct 212 ms 1784 KB Output is correct