QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#510152 | #9156. 百万富翁 | Arapak | 91.00003 | 2077ms | 102232kb | C++20 | 3.6kb | 2024-08-08 21:33:38 | 2024-08-08 21:33:38 |
Judging History
answer
#include "bits/stdc++.h"
#include "richest.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#ifdef DEBUG
auto& operator<<(auto& os, const pair<auto,auto> &p) {
return os<<"("<<p.first<<", "<<p.second<<")";
}
auto& operator<<(auto& os, const auto &v) {
os<<"{";
for(auto it=begin(v);it!=v.end();++it) {
if(it!=begin(v)) os<<", ";
os<<(*it);
}
return os<<"}";
}
void dbg_out(auto... x) {
((cerr<<' '<<x), ...) << endl;
}
#define dbg(x...) cerr<<"("<<#x<<"):", dbg_out(x);
#else
#define dbg(...)
#endif
vi solve_k(vector<int> index, int K) {
dbg(index);
int n = sz(index);
int f = n / K;
int r = n % K;
if(f < r) {
vector<pii> q;
auto query_k = [&](int ind, int k) {
rep(i,0,k)
rep(j,i+1,k)
q.emplace_back(ind + i, ind + j);
};
for(int i=0;i<n;i+=K)
query_k(i, min(K, n-i));
vi a, b;
for(auto [x, y] : q) {
a.push_back(index[x]);
b.push_back(index[y]);
}
dbg(a, b);
vi res = ask(a, b);
dbg(res);
auto get_num = [](int k) {
return k * (k - 1) / 2;
};
vi new_index;
auto get_best = [&](int ind, int ind_res, int k) {
int number = get_num(k);
rep(i,0,k) {
int num = 0;
rep(j,0,number)
num += index[ind + i] == res[ind_res + j];
if(num == k-1) {
new_index.push_back(index[ind + i]);
break;
}
}
};
for(int i=0;i<n;i+=K) {
int start = get_num(K) * (i / K);
get_best(i, start, min(K, n-i));
}
dbg(new_index);
return new_index;
}
dbg("TUTAJ");
vector<pii> q;
auto query_k = [&](int ind, int k) {
rep(i,0,k)
rep(j,i+1,k)
q.emplace_back(ind + i, ind + j);
};
for(int i=0;i<K*(f-r);i+=K)
query_k(i, K);
for(int i=K*(f-r);i<n;i+=K+1)
query_k(i, K+1);
vi a, b;
for(auto [x, y] : q) {
a.push_back(index[x]);
b.push_back(index[y]);
}
dbg(a, b);
vi res = ask(a, b);
dbg(res);
auto get_num = [](int k) {
return k * (k - 1) / 2;
};
vi new_index;
auto get_best = [&](int ind, int ind_res, int k) {
int number = get_num(k);
rep(i,0,k) {
int num = 0;
rep(j,0,number)
num += index[ind + i] == res[ind_res + j];
if(num == k-1) {
new_index.push_back(index[ind + i]);
break;
}
}
};
for(int i=0;i<K*(f-r);i+=K) {
int start = get_num(K) * (i / K);
get_best(i, start, K);
}
for(int i=K*(f-r);i<n;i+=K+1) {
int start = get_num(K) * (f-r) + get_num(K+1) * (i - K*(f-r)) / (K+1);
get_best(i, start, K+1);
}
dbg(new_index);
return new_index;
}
int richest(int N, int T, int S) {
if(T == 1) {
vi a, b;
rep(i,0,N) rep(j,i+1,N) {
a.push_back(i);
b.push_back(j);
}
auto res = ask(a, b);
sort(all(res));
int prev = -1;
int num = 0;
for(auto x : res) {
if(x == prev) {
num++;
if(num == N-1) return x;
}
else {
prev = x;
num = 1;
}
}
assert(false);
}
vi perm(N);
iota(all(perm), 0);
// const vi v = {2, 2, 2, 2, 3, 6, 19, 183};
const vi v = {2, 2, 2, 2, 3, 6, 19, 183};
// const vi v = {3, 3, 3};
// int product = 1;
// for(auto x : v)
// product *= x;
// assert(product >= 1000000);
for(const auto x : v) {
perm = solve_k(perm, x);
if(sz(perm) == 1) return perm[0];
}
return -1;
}
// n * (k-1) / 2
// 1099944
// 2: n / 2 -> n / 2
// 2: n / 4 -> n / 4
// 2: n / 8 -> n / 8
// 3: n / 8 -> n / 24
// SUM: n
詳細信息
Pretests
Pretest #1:
score: 15
Accepted
time: 739ms
memory: 25304kb
input:
1000 1 499500 957319859
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Pretest #2:
score: 76
Acceptable Answer
time: 2077ms
memory: 102148kb
input:
1000000 20 2000000 29091473
output:
Partially correct Case 2, 76 / 85, maxt = 8, maxs = 1099947 708834003727782761 0.894118 11625001216319896173
result:
points 0.894118 Partially correct Case 2, 76 / 85, maxt = 8, maxs = 1099947
Final Tests
Test #1:
score: 15
Accepted
time: 729ms
memory: 25240kb
input:
1000 1 499500 957319857
output:
Correct 7127326332295218295 1.000000 1331569654267968081
result:
points 1.0 Correct
Test #2:
score: 76
Acceptable Answer
time: 2063ms
memory: 102232kb
input:
1000000 20 2000000 29091471
output:
Partially correct Case 2, 76 / 85, maxt = 8, maxs = 1099947 708834003727782761 0.894118 11625001216319896173
result:
points 0.894118 Partially correct Case 2, 76 / 85, maxt = 8, maxs = 1099947