답안 #130032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130032 2019-07-13T19:17:23 Z TadijaSebez Olympiads (BOI19_olympiads) C++11
31 / 100
2000 ms 142916 KB
#include <bits/stdc++.h>
using namespace std;
const int N=505;
const int K=6;
int n,k,c;
int a[K][N];
bool in[N];
set<string> was;
int Val(vector<int> state)
{
	int ans=0;
	for(int i=0;i<k;i++)
	{
		int tmp=0;
		for(int j:state) tmp=max(tmp,a[i][j]);
		ans+=tmp;
	}
	return ans;
}
string ToString(vector<int> state)
{
	string ans;
	for(int i=0;i<k;i++) ans+=(char)state[i];
	return ans;
}
int main()
{
	scanf("%i %i %i",&n,&k,&c);
	for(int i=1;i<=n;i++) for(int j=0;j<k;j++) scanf("%i",&a[j][i]);
	vector<int> st;
	for(int j=0;j<k;j++)
	{
		int b=0;
		for(int i=1;i<=n;i++) if(!in[i] && (b==0 || a[j][i]>a[j][b])) b=i;
		st.push_back(b);
		in[b]=1;
	}
	sort(st.begin(),st.end());
	priority_queue<pair<int,vector<int>>> pq;
	auto Push=[&](vector<int> state)
	{
		sort(state.begin(),state.end());
		string s=ToString(state);
		if(!was.count(s))
		{
			pq.push({Val(state),state});
			was.insert(s);
		}
	};
	Push(st);
	int ans=0;
	while(c--)
	{
		ans=pq.top().first;
		vector<int> state=pq.top().second;
		pq.pop();
		for(int i=1;i<=n;i++)
		{
			bool ok=1;
			for(int j:state) if(j==i) ok=0;
			if(!ok) continue;
			vector<int> nxt=state;
			for(int j=0;j<k;j++)
			{
				nxt[j]=i;
				Push(nxt);
				nxt[j]=state[j];
			}
		}
	}
	printf("%i\n",ans);
	return 0;
}

Compilation message

olympiads.cpp: In function 'int main()':
olympiads.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i %i",&n,&k,&c);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:29:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) for(int j=0;j<k;j++) scanf("%i",&a[j][i]);
                                             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 717 ms 9580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 13248 KB Output is correct
2 Correct 262 ms 11764 KB Output is correct
3 Correct 265 ms 12384 KB Output is correct
4 Correct 240 ms 11820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2060 ms 142916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 717 ms 9580 KB Output isn't correct
2 Halted 0 ms 0 KB -