답안 #648521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648521 2022-10-06T19:03:59 Z inksamurai Izbori (COCI17_izbori) C++17
78 / 80
36 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3Rz7lEu ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

signed main(){
_3Rz7lEu;
	int n,m,id;
	cin>>n>>m>>id;
	id-=1;
	vec(vi) a(n,vi(m));
	rep(i,n){
		rep(j,m){
			cin>>a[i][j];
			a[i][j]--;
		}
	}
	int p0=-1,p1=m;
	rep(msk,1<<m){
		vi cnt(m);
		rep(i,n){
			rep(j,m){
				int v=a[i][j];
				if(msk>>v&1) continue;
				cnt[v]+=1;
				break;
			}
		}
		int ma=-1;
		int pvt=-1;
		rep(v,m){
			if(cnt[v]>ma)ma=cnt[v],pvt=v;
		}
		if(msk==0)p0=pvt+1;
		else if(pvt==id){
			p1=min(p1,__builtin_popcount(msk));
		}
	}
	cout<<p0<<"\n";
	cout<<p1<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 7 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Partially correct 5 ms 212 KB Partially correct
12 Correct 16 ms 328 KB Output is correct
13 Correct 28 ms 212 KB Output is correct
14 Correct 14 ms 336 KB Output is correct
15 Correct 5 ms 328 KB Output is correct
16 Correct 36 ms 212 KB Output is correct
17 Correct 17 ms 324 KB Output is correct
18 Correct 33 ms 212 KB Output is correct
19 Correct 36 ms 308 KB Output is correct
20 Correct 35 ms 212 KB Output is correct