QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527112#9156. 百万富翁TheRaptorCompile Error//C++172.0kb2024-08-22 10:22:492024-08-22 10:22:49

Judging History

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

  • [2024-08-22 10:22:49]
  • 评测
  • [2024-08-22 10:22:49]
  • 提交

answer

#include "richest.h"
#include <bits/stdc++.h>
using namespace std;
static int N, T, S, r, t, s;
static vector<int> W;
vector<int> ask(vector<int> i, vector<int> j) {
    ++t;
    if (t > T)
        throw string("Too many queries");
    if (i.size() != j.size())
        throw string("Invalid query: i and j must have the same size");
    int m = i.size();
    s += m;
    if (s > S)
        throw string("Too many total elements in queries");
    vector<int> res(m);
    for (int k = 0; k < m; k++) {
        if (i[k] < 0 || i[k] >= N || j[k] < 0 || j[k] >= N)
            throw string("Invalid query: index out of bounds");
        res[k] = W[i[k]] > W[j[k]] ? i[k] : j[k];
    }
    return res;
}
int richest(int n, int t, int s){
	vector<int> a,b,ret;
	if(t==1){
		assert(n==1000);
		for(int i=0; i<n; i++){
			for(int j=i+1; j<n; j++){
				a.push_back(i);
				b.push_back(j);
			}
		}
		ret=ask(a,b);
		int ans=0;
		for(int i=0; i<(int)ret.size(); i++){
			if(a[i]==ans) ans=ret[i];
		}
		return ans;
	}
	vector<int> alive,tmp;
	for(int i=0; i<n; i++) alive.push_back(i);
	long long can=1099950;
	while((int)alive.size()>1){
		int m=alive.size();
		int buc=2;
		if((long long)m*(m-1)/2<=can) buc=m;
		else{
			while((long long)(m+buc-1)/buc*buc*(buc-1)/2<can*4/7){
				buc++;
				if(buc>m) break;
			}
			buc--;
		}
		//cout << buc << '\n';
		//cout << (m+buc-1)/buc*buc*(buc-1)/2 << '\n';
		a.clear(); b.clear();
		for(int i=0; i<m; i+=buc){
			for(int j=0; j<buc; j++){
				for(int k=j+1; k<buc; k++){
					if(i+j>=m||i+j>=m) continue;
					a.push_back(alive[i+j]);
					b.push_back(alive[i+k]);
					can--;
				}
			}
		}
		cout << a.size() << '\n';
		ret=ask(a,b);
		int cnt=0;
		for(int i=0; i<m; i+=buc){
			int best=alive[i];
			for(int j=0; j<buc; j++){
				for(int k=j+1; k<buc; k++){
					if(i+j>=m||i+j>=m) continue;
					if(a[cnt]==best) best=ret[cnt];
					cnt++;
				}
			}
			tmp.push_back(best);
		}
		swap(tmp,alive);
		tmp.clear();
	}
	return alive[0];
}

Details

/usr/bin/ld: /tmp/ccjfPgbw.o: in function `ask(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
answer.code:(.text+0x0): multiple definition of `ask(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/ccY8XJCx.o:implementer.cpp:(.text+0xee0): first defined here
collect2: error: ld returned 1 exit status