QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722091#9156. 百万富翁Azusa100 ✓4616ms112068kbC++142.4kb2024-11-07 17:47:322024-11-07 17:47:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 17:47:32]
  • 评测
  • 测评结果:100
  • 用时:4616ms
  • 内存:112068kb
  • [2024-11-07 17:47:32]
  • 提交

answer

#include "richest.h"
#include<bits/stdc++.h>
 
using namespace std;
 
std::vector <int> ask(std::vector <int> a, std::vector <int> b);

namespace sub1{
	const int maxn=1010;
	int id[maxn];
	bool win[maxn][maxn];

	inline int sol(int n){
		vector<int> a,b,c;
		for(int i=0;i<n;i++) id[i]=i;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				win[i][j]=false;
		for(int i=0;i<n;i++)
			for(int j=i+1;j<n;j++){
				a.push_back(i);
				b.push_back(j);
			} 
		c=ask(a,b);
		for(int i=0;i<a.size();i++){
			int x=a[i],y=b[i],z=c[i];
			if(z==x) win[x][y]=true;
			else win[y][x]=true;
		} 
		for(int i=0;i<n;i++)
			for(int j=i+1;j<n;j++)
				if(win[id[i]][id[j]]) swap(id[i],id[j]);  
		return id[n-1];		
	}
}

namespace sub2{
	const int maxn=1e6+10;

	map<pair<int,int>,bool> win;

	inline void merge(vector<int> &vec,int k){
		int sz=vec.size(),cnt,idx=0,rest,step=k-1,s;
		s=sz/k; cnt=sz%k;
		while(cnt%(k-1)!=0){
			s--; cnt+=k;
		}
		rest=cnt/(k-1);
		vector<int> a,b,c,t;
		if(k==3){
			step=4; rest=1;
		}
		if(k==6){
			s=3471; step=7; rest=1;
		}
		if(k==19){
			s=178; step=18; rest=5;
		}
		for(int i=k-1,j=0,ps=1;i<sz && ps<=s;i+=k,ps++){
			for(int l=j;l<=i;l++)
				for(int r=l+1;r<=i;r++){
					a.push_back(vec[l]);
					b.push_back(vec[r]);
				}
			j=i+1;
		}
		int lst=k*(s-1)+(k-1)+1;
		for(int i=lst+step-1,j=lst,ps=1;i<sz && ps<=rest;i+=step,ps++){
			for(int l=j;l<=i;l++)
				for(int r=l+1;r<=i;r++){
					a.push_back(vec[l]);
					b.push_back(vec[r]);
				}
			j=i+1;
		}
		c=ask(a,b);
		win.clear();
		for(int i=0;i<a.size();i++){
			int x=a[i],y=b[i],z=c[i];
			if(z==x) win[{x,y}]=true;
			else win[{y,x}]=true;
		}
		for(int i=k-1,j=0,ps=1;i<sz && ps<=s;i+=k,ps++){
			for(int l=j;l<=i;l++)
				for(int r=l+1;r<=i;r++)
					if(win[{vec[l],vec[r]}]==true) swap(vec[l],vec[r]); 
			t.push_back(vec[i]);
			j=i+1;
		}
		for(int i=lst+step-1,j=lst,ps=1;i<sz && ps<=rest;i+=step,ps++){
			for(int l=j;l<=i;l++)
				for(int r=l+1;r<=i;r++)
					if(win[{vec[l],vec[r]}]==true) swap(vec[l],vec[r]); 
			t.push_back(vec[i]);
			j=i+1;
		}
		vec.swap(t);
	}

	inline int sol(int n){
		vector<int> vec;
		for(int i=0;i<n;i++) vec.push_back(i);
		for(int i=4;i--;) merge(vec,2);
		merge(vec,3); merge(vec,6); merge(vec,19); 
		merge(vec,183);
		return vec.back();
	}
}

int richest(int N, int T, int S) {
	if(N<=1000) return sub1::sol(N);
	else return sub2::sol(N);
}

详细


Pretests

Pretest #1:

score: 15
Accepted
time: 639ms
memory: 27536kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 85
Accepted
time: 4605ms
memory: 111920kb

input:

1000000 20 2000000 29091473

output:

Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944
7610580723948932399
1.000000
1331569654267968081

result:

points 1.0 Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944


Final Tests

Test #1:

score: 15
Accepted
time: 623ms
memory: 26200kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 85
Accepted
time: 4616ms
memory: 112068kb

input:

1000000 20 2000000 29091471

output:

Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944
7610580723948932399
1.000000
1331569654267968081

result:

points 1.0 Correct Case 2, 85 / 85, maxt = 8, maxs = 1099944