QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602597#9156. 百万富翁Littlelu15 668ms76004kbC++142.1kb2024-10-01 11:05:202024-10-01 11:05:21

Judging History

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

  • [2024-10-01 11:05:21]
  • 评测
  • 测评结果:15
  • 用时:668ms
  • 内存:76004kb
  • [2024-10-01 11:05:20]
  • 提交

answer

#include <bits/stdc++.h>
#include "richest.h"
using namespace std;
int solve0(){
    vector<int> aska,askb,resp;
    int cnt=0;
    for(int i=0;i<1000;++i) for(int j=i+1;j<1000;++j){
        aska.push_back(i),askb.push_back(j),++cnt;
    }
    resp=ask(aska,askb);
    vector<int> to[1000],in(1000),ans;
    for(int i=0;i<cnt;++i){
        if(resp[i]==aska[i]) to[askb[i]].push_back(aska[i]),in[aska[i]]++;
        else to[aska[i]].push_back(askb[i]),in[askb[i]]++;
    }
    queue<int> que;
    for(int i=0;i<1000;++i) if(in[i]==0) que.push(i);
    while(!que.empty()){
        int u=que.front();que.pop();
        ans.push_back(u);
        for(int v:to[u]){
            --in[v];
            if(in[v]==0) que.push(v);
        }
    }
    return ans[ans.size()-1];
}
int solve1(){
    int n=1000000,h=n;
    vector<int> asks(h);
    for(int i=0;i<h;++i) asks[i]=i;
    int aq=0;
    while(h!=1){
        if(h>=300){
            int x2=-1,cnt=0;
            if(h%2==1) x2=h-1;
            vector<int> aska,askb,resp;
            for(int i=0;i<h/2;++i)
                aska.push_back(asks[i*2]),askb.push_back(asks[i*2+1]),++cnt;
            resp=ask(aska,askb);
            asks.clear();
            if(x2!=-1) asks.push_back(x2);
            for(int i=0;i<cnt;++i){
                if(resp[i]==aska[i]) asks.push_back(aska[i]);
                else asks.push_back(askb[i]);
            }
            aq+=cnt;
            h=asks.size();
        }else{
            vector<int> aska,askb,resp;
            int cnt=0;
            for(int i=0;i<h;++i) for(int j=i+1;j<h;++j){
                aska.push_back(asks[i]),askb.push_back(asks[j]),++cnt;
            }
            // alex;
            resp=ask(aska,askb);
            map<int,int> out;
            for(int i=0;i<cnt;++i){
                if(resp[i]==aska[i]) out[askb[i]]++;
                else out[aska[i]]++;
            }
            int ans;
            for(int i=0;i<h;++i) if(out[asks[i]]==0) ans=asks[i];
            asks.resize(1);
            asks[0]=ans,h=1;
        }
    }
    return asks[0];
}
int richest(int n,int t,int s){
    if(n==1000) return solve0();
    else return solve1();
}

Details

Tip: Click on the bar to expand more detailed information

Pretests

Pretest #1:

score: 15
Accepted
time: 668ms
memory: 22432kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 0
Wrong Answer
time: 218ms
memory: 75964kb

input:

1000000 20 2000000 29091473

output:

Wrong answer
4459638610240858557
0.000000
6906350380861515327

result:

points 0.0 Wrong answer


Final Tests

Test #1:

score: 15
Accepted
time: 641ms
memory: 22484kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 0
Wrong Answer
time: 244ms
memory: 76004kb

input:

1000000 20 2000000 29091471

output:

Wrong answer
4459638610240858557
0.000000
6906350380861515327

result:

points 0.0 Wrong answer