Submission #104176

# Submission time Handle Problem Language Result Execution time Memory
104176 2019-04-04T09:19:15 Z Fasho Izbori (COCI17_izbori) C++14
80 / 80
76 ms 512 KB
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,m,k,ar[105][20],sum,mn=INT_MAX,mark[20],mark2[20],cnt[N];

void f(int ind,int mask)
{
	if(ind>m+1)
		return;
	memset(mark,0,sizeof(mark));
	memset(mark2,0,sizeof(mark2));
	ll tutmac=0;
	for(int i=1;i<=ind;i++)
	{
		int x=(1<<i);
		if(x&mask)
			mark[i]=1,tutmac++;
	}
	int tut=0;

	int x=mask;
	int y=(1<<ind);
	x=mask|y;

	if(ind>1 && mask==0)
	{
		f(ind+1,x);
		f(ind+1,mask);
		return;
	}

	ll mki=0;

	for(int i=1;i<=n;i++)
	{
		int tmp=0;
		for(int j=1;j<=m;j++)
		{
			// if(mark[ar[i][j]])
			// 	q++;
			if(!tmp && !mark[ar[i][j]])
			{
				mark2[ar[i][j]]++;
				if(mark2[ar[i][j]]>mark2[mki])
					mki=ar[i][j];
				tmp=1;

			if(mark2[ar[i][j]]==mark2[mki])
				mki=min(mki,ar[i][j]);
			}

		}

		

		}
	// cout<<mask<<sp<<mki<<sp<<k<<sp<<tutmac<<endl;

	if(mki==k)
	{
		mn=min(tutmac,mn);
		return;

	}
	if(mask==0)
	{

		f(ind+1,x);
		f(ind+1,mask);
		return;
	} 
		f(ind+1,x);
		f(ind+1,mask);
}


int main()
{
	fast;
	cin>>n>>m>>k;
	fo(i,1,n)
		fo(j,1,m)
			cin>>ar[i][j];

	ll mkii=0;
	
	fo(i,1,n)
	{
		cnt[ar[i][1]]++;	
		if(cnt[ar[i][1]]>cnt[mkii])
			mkii=ar[i][1];
		else if(cnt[ar[i][1]]==cnt[mkii])
			mkii=min(mkii,ar[i][1]);
	}
	cout<<mkii<<endl;

	f(1,0);
	cout<<mn;
}

Compilation message

izbori.cpp: In function 'void f(int, int)':
izbori.cpp:35:6: warning: unused variable 'tut' [-Wunused-variable]
  int tut=0;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 4 ms 404 KB Output is correct
4 Correct 20 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 12 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 33 ms 400 KB Output is correct
13 Correct 65 ms 404 KB Output is correct
14 Correct 28 ms 440 KB Output is correct
15 Correct 8 ms 384 KB Output is correct
16 Correct 75 ms 404 KB Output is correct
17 Correct 28 ms 384 KB Output is correct
18 Correct 72 ms 384 KB Output is correct
19 Correct 76 ms 404 KB Output is correct
20 Correct 76 ms 384 KB Output is correct