# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104166 | Fasho | Izbori (COCI17_izbori) | C++14 | 78 ms | 496 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
if(cnt[ar[i][1]]==cnt[mkii])
mkii=min(mkii,ar[i][1]);
}
cout<<mkii<<endl;
f(1,0);
cout<<mn;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |