답안 #104169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104169 2019-04-04T09:12:48 Z Fasho Izbori (COCI17_izbori) C++14
66 / 80
72 ms 400 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]]==cnt[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;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Partially correct 9 ms 384 KB Partially correct
3 Correct 3 ms 384 KB Output is correct
4 Partially correct 16 ms 384 KB Partially correct
5 Partially correct 5 ms 384 KB Partially correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Partially correct 14 ms 384 KB Partially correct
9 Correct 8 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 26 ms 384 KB Output is correct
13 Partially correct 57 ms 400 KB Partially correct
14 Correct 28 ms 384 KB Output is correct
15 Partially correct 9 ms 384 KB Partially correct
16 Correct 44 ms 384 KB Output is correct
17 Correct 27 ms 384 KB Output is correct
18 Partially correct 62 ms 384 KB Partially correct
19 Correct 64 ms 384 KB Output is correct
20 Correct 72 ms 400 KB Output is correct