답안 #124862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124862 2019-07-04T04:50:02 Z 김세빈(#3048) Olympiads (BOI19_olympiads) C++14
100 / 100
50 ms 2172 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

priority_queue <pll> Q;
set <pll> S;
ll A[555][6], B[555][6], C[555][6];
pll X[6][555];
ll n, k, c;

pll enc(vector <ll> &V)
{
	pll ret(0, 0);
	ll i;
	
	for(i=0; i<k; i++){
		ret.first += A[C[V[i]][i]][i];
		ret.second = ret.second * n + V[i];
	}
	
	return ret;
}

vector <ll> dec(ll x)
{
	vector <ll> ret(6);
	ll i;
	
	for(i=k-1; i>=0; i--){
		ret[i] = x % n; x /= n;
	}
	
	return ret;
}

ll count(vector <ll> &V)
{
	ll ret, i, j, t1, t2, s1, s2;
	
	ret = 1; s1 = k; s2 = 0;
	
	for(i=0; i<n; i++){
		for(j=0, t1=0, t2=0; j<k; j++){
			if(B[i][j] < V[j]) t1 = 1;
			else if(B[i][j] == V[j]) t2 = 1;
		}
		if(t1 && t2) return 0;
		else if(t2) s1 --;
		else if(!t1) s2 ++;
	}
	
	for(i=1; i<=s1; i++, s2--){
		ret = ret * s2 / i;
	}
	
	return ret;
}

int main()
{
	vector <ll> V;
	ll i, j;
	pll p;
	
	scanf("%lld%lld%lld", &n, &k, &c);
	
	for(i=0; i<n; i++){
		for(j=0; j<k; j++){
			scanf("%lld", A[i] + j);
			X[j][i] = pll(-A[i][j], i);
		}
	}
	
	for(i=0; i<k; i++){
		sort(X[i], X[i] + n);
		for(j=0; j<n; j++){
			B[X[i][j].second][i] = j;
			C[j][i] = X[i][j].second;
		}
	}
	
	V = vector <ll> (k, 0); p = enc(V);
	S.insert(p); Q.push(p);
	
	for(; !Q.empty(); ){
		V = dec(Q.top().second);
		c -= count(V);
		if(c <= 0){
			printf("%lld\n", Q.top().first);
			return 0;
		}
		Q.pop();
		
		for(i=0; i<6; i++){
			if(V[i] + 1 < n){
				V[i] ++; p = enc(V);
				if(S.find(p) == S.end()){
					S.insert(p); Q.push(p);
				}
				V[i] --;
			}
		}
	}
	
	return 0;
}

Compilation message

olympiads.cpp: In function 'int main()':
olympiads.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld", &n, &k, &c);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:72:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", A[i] + j);
    ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 7 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 50 ms 2172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 6 ms 988 KB Output is correct
4 Correct 6 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 18 ms 1144 KB Output is correct
4 Correct 19 ms 1400 KB Output is correct
5 Correct 8 ms 1144 KB Output is correct
6 Correct 14 ms 2164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 7 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 50 ms 2172 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 4 ms 760 KB Output is correct
7 Correct 6 ms 988 KB Output is correct
8 Correct 6 ms 888 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 18 ms 1144 KB Output is correct
12 Correct 19 ms 1400 KB Output is correct
13 Correct 8 ms 1144 KB Output is correct
14 Correct 14 ms 2164 KB Output is correct
15 Correct 16 ms 888 KB Output is correct
16 Correct 7 ms 760 KB Output is correct
17 Correct 20 ms 1360 KB Output is correct
18 Correct 17 ms 1144 KB Output is correct
19 Correct 2 ms 376 KB Output is correct