QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#504178#9156. 百万富翁zdczdc100 ✓2469ms113284kbC++201.6kb2024-08-04 09:41:532024-08-04 09:41:56

Judging History

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

  • [2024-08-04 09:41:56]
  • 评测
  • 测评结果:100
  • 用时:2469ms
  • 内存:113284kb
  • [2024-08-04 09:41:53]
  • 提交

answer

#include "richest.h"
#include <bits/stdc++.h>
// #define int int64_t
#define ALL(x) begin(x), end(x)
#define All(x, l, r) &x[l], &x[r] + 1
using namespace std;
using ll = long long;
template <typename T> using vec = vector<T>;

const int kLim = 1e6 + 5;
array<int, kLim> cnt;

vec<int> brute(const vec<vec<int>>& id) {
  int n = id.size();
  vec<int> a, b, l (n), r (n), res (n);
  int siz = 0;
  for(auto& k : id) siz += k.size() * (k.size() - 1) / 2;
  a.reserve(siz); b.reserve(siz);
  for(int i = 0; i < n; i++) {
    auto& v = id[i];
    l[i] = a.size();
    for(int j = 0; j < v.size(); j++)
      for(int k = j + 1; k < v.size(); k++) {
        a.push_back(v[j]);
        b.push_back(v[k]);
      }
    r[i] = a.size();
  }
  auto c = ask(a, b);
  for(int i = 0; i < n; i++) {
    auto& v = id[i];
    for(int j = l[i]; j < r[i]; j++) cnt[c[j]]++;
    for(int k : v)
      if(cnt[k] + 1 == v.size()) res[i] = k;
    for(int j = l[i]; j < r[i]; j++) cnt[c[j]]--;
  }
  return res;
}

int solve(vec<int> id, vec<int> way) {
  for(int i = 0; i < way.size(); i++) {
    int n = id.size();
    int c = way[i], q = n / c, r = n % c;
    vec<vec<int>> qry;
    vec<int> t (q + 1);
    for(int p = 0; p < n; ) {
      int siz = q + ((r--) > 0);
      if(t.size() > siz) t.pop_back();
      memcpy(&t[0], &id[p], siz * sizeof(int));
      p += siz; qry.push_back(t);
    }
    id = brute(qry);
  }
  return id[0];
}

int richest(int n, int T, int S) {
  vec<int> id (n);
  iota(ALL(id), 0);
  if(T == 1) return brute({id})[0];
  return solve(id, {500000, 250000, 125000, 62500, 20833, 3472, 183, 1});
}

詳細信息


Pretests

Pretest #1:

score: 15
Accepted
time: 604ms
memory: 22696kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 85
Accepted
time: 2453ms
memory: 113284kb

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: 596ms
memory: 22560kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 85
Accepted
time: 2469ms
memory: 106044kb

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