QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#488047#9156. 百万富翁PinkRabbit#100 ✓2023ms101340kbC++202.1kb2024-07-23 15:37:372024-07-23 15:37:39

Judging History

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

  • [2024-07-23 15:37:39]
  • 评测
  • 测评结果:100
  • 用时:2023ms
  • 内存:101340kb
  • [2024-07-23 15:37:37]
  • 提交

answer

#include "richest.h"

int richest(int N, int T, int S) {
    if (T == 1 && S >= (long long)N * (N - 1) / 2) {
        int m = N * (N - 1) / 2;
        std::vector<int> a, b;
        a.reserve(m);
        b.reserve(m);
        for (int i = 0; i < N; ++i)
            for (int j = i + 1; j < N; ++j)
                a.push_back(i),
                b.push_back(j);
        auto c = ask(a, b);
        std::vector<int> win(N, 0);
        for (int i = 0; i < m; ++i)
            ++win[c[i]];
        for (int i = 0; i < N; ++i)
            if (win[i] == N - 1)
                return i;
    }
    // N == 1000000
    const int ns[] = {1000000, 500000, 250000, 125000, 62497, 20832, 3472, 183, 1};
    std::vector<int> cand(N);
    for (int i = 0; i < N; ++i)
        cand[i] = i;
    for (int t_ = 0; t_ < 8; ++t_) {
        int n1 = ns[t_], n2 = ns[t_ + 1];
        int a1 = n1 / n2;
        int a2 = a1 + 1;
        int c2 = n1 % n2;
        int c1 = n2 - c2;
        int m = a1 * (a1 - 1) / 2 * c1 + a2 * (a2 - 1) / 2 * c2;
        std::vector<int> a, b;
        a.reserve(m), b.reserve(m);
        for (int i = 0, j1 = 0, k = 0; i < n2; ++i) {
            int j2 = j1 + (k < c1 ? (++k, a1) : a2);
            for (int j = j1; j < j2; ++j)
                for (int j_ = j + 1; j_ < j2; ++j_)
                    a.push_back(cand[j]),
                    b.push_back(cand[j_]);
            j1 = j2;
        }
        auto c = ask(a, b);
        std::vector<int> ncand(n2);
        for (int i = 0, j1 = 0, k = 0, p = 0; i < n2; ++i) {
            int j2 = j1 + (k < c1 ? (++k, a1) : a2);
            static int win[1000000];
            for (int j = j1; j < j2; ++j)
                win[cand[j]] = 0;
            for (int j = j1; j < j2; ++j)
                for (int j_ = j + 1; j_ < j2; ++j_)
                    ++win[c[p++]];
            for (int j = j1; j < j2; ++j)
                if (win[cand[j]] == j2 - j1 - 1)
                    ncand[i] = cand[j];
            j1 = j2;
        }
        cand.swap(ncand);
    }
    return cand[0];
}

詳細信息


Pretests

Pretest #1:

score: 15
Accepted
time: 612ms
memory: 20616kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 85
Accepted
time: 2023ms
memory: 90336kb

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: 618ms
memory: 20752kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 85
Accepted
time: 2013ms
memory: 101340kb

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