QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#509930#9156. 百万富翁Franuch#15 625ms130956kbC++171.6kb2024-08-08 19:55:272024-08-08 19:55:29

Judging History

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

  • [2024-08-08 19:55:29]
  • 评测
  • 测评结果:15
  • 用时:625ms
  • 内存:130956kb
  • [2024-08-08 19:55:27]
  • 提交

answer

#include "richest.h"
#include <bits/stdc++.h>

using namespace std;
typedef int ll;

ll on2(ll n) {
    vector<ll> a, b;
    for (ll i = 1; i < n; i++) {
        for (ll j = 0; j < i; j++) {
            a.push_back(i);
            b.push_back(j);
        }
    }

    vector<ll> c = ask(a, b);
    std::reverse(c.begin(), c.end());

    vector<vector<bool>> cmp(n, vector<bool>(n, true));
    for (ll i = 1; i < n; i++)
        for (ll j = 0; j < i; j++) {
            cmp[i][j] = c.back() == i;
            cmp[j][i] = c.back() == j;
            c.pop_back();
        }

    for (ll i = 0; i < n; i++) {
        bool good = true;
        for (ll j = 0; j < n; j++)
            good = good and cmp[i][j];

        if (good)
            return i;
    }
    return 0;
}

ll onlogn(ll n) {
    mt19937 rng(3498);

    vector<ll> p(n);
    std::iota(p.begin(), p.end(), 0);

    while (p.size() > 1) {
        uniform_int_distribution<> uid(0, p.size() - 1);
        ll pivot = uid(rng);

        vector<ll> a(p.size() - 1, p[pivot]);
        vector<ll> b;
        b.reserve(p.size() - 1);
        for (auto &i : p)
            if (i != p[pivot])
                b.push_back(i);

        vector<ll> c = ask(a, b);

        vector<ll> t = {p[pivot]};
        t.reserve(n);
        for (ll &i : c)
            if (i != t[0])
                t.push_back(i);

        swap(p, t);
    }

    return p[0];
}

ll richest(ll N, ll T, ll S) {
    if (ll(N) * ll(N - 1) / 2ll <= (ll)S and N <= 1000) {
        return on2(N);
    } else {
        return onlogn(N);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Pretests

Pretest #1:

score: 15
Accepted
time: 610ms
memory: 23004kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 0
Wrong Answer
time: 547ms
memory: 130956kb

input:

1000000 20 2000000 29091473

output:

Too many total elements in queries
1469670942222006797
0.000000
6906350380861515327

result:

points 0.0 Too many total elements in queries


Final Tests

Test #1:

score: 15
Accepted
time: 625ms
memory: 22896kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 0
Wrong Answer
time: 530ms
memory: 130736kb

input:

1000000 20 2000000 29091471

output:

Too many total elements in queries
1469670942222006797
0.000000
6906350380861515327

result:

points 0.0 Too many total elements in queries