QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533375#9156. 百万富翁chenshi91.00003 2243ms190144kbC++171.8kb2024-08-25 21:07:012024-08-25 21:07:01

Judging History

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

  • [2024-08-25 21:07:01]
  • 评测
  • 测评结果:91.00003
  • 用时:2243ms
  • 内存:190144kb
  • [2024-08-25 21:07:01]
  • 提交

answer

#include "richest.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long inf = 1e18;
int init, w[9][N];
long long f[9][N];
void upd(int i, int j, int k) {
	int c2 = j % k, c1 = j / k - c2;
	if(c1 < 0) return;
	long long res = k * (k - 1ll) / 2 * c1 + k * (k + 1ll) / 2 * c2 + f[i - 1][j / k];
	if(res < f[i][j]) f[i][j] = res, w[i][j] = k;
}
void Init() {
	init = 1;
	for(int i = 2; i < N; i++) f[0][i] = inf;
	for(int i = 1; i < 9; i++)
		for(int j = 2; j < N; j++) {
			f[i][j] = inf;
			int lim = ((j <= N / 8) ? min(20, j) : 2);
			for(int  k = 2; k <= lim; k++) upd(i, j, k);
			upd(i, j, j);
		}
}
int richest(int N, int T, int S) {
	vector<int> l, r, ok(N, 1), cand(N);
	iota(cand.begin(), cand.end(), 0);
	auto query = [&](int L, int R) {
		for(int i = L; i < R; i++)
			for(int j = L; j < i; j++)
				l.push_back(cand[i]), r.push_back(cand[j]);
	};
	auto solve = [&]() {
		auto res = ask(l, r);
		for(int i = 0; i < (int)l.size(); i++)
			ok[l[i]] &= (res[i] == l[i]), ok[r[i]] &= (res[i] == r[i]);
	};
	if(T == 1) {
		vector<int>().swap(l), vector<int>().swap(r);
		l.reserve(N * (N - 1) / 2), r.reserve(N * (N - 1) / 2);
		query(0, N);
		solve();
		for(int i = 0; i < N; i++) if(ok[i]) return i;
	}
	if(!init) Init(), cerr << f[8][::N - 1] << endl;
	for(int t = 8; (int)cand.size() > 1; t--) {
		int n = cand.size(), v = w[t][n], c2 = n % v, c1 = n / v - c2,
			len = v * (v - 1) / 2 * c1 + v * (v + 1) / 2 * c2;
		vector<int>().swap(l), vector<int>().swap(r);
		l.reserve(len), r.reserve(len);
		for(int i = 0; i < c1; i++)
			query(i * v, (i + 1) * v);
		for(int i = 0; i < c2; i++)
			query(c1 * v + i * (v + 1), c1 * v + (i + 1) * (v + 1));
		solve();
		vector<int> nxt;
		nxt.reserve(n / v);
		for(auto x: cand) if(ok[x]) nxt.push_back(x);
		cand = nxt;
	}
	return cand[0];
}

Details

Tip: Click on the bar to expand more detailed information

Pretests

Pretest #1:

score: 15
Accepted
time: 611ms
memory: 19504kb

input:

1000 1 499500 957319859

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Pretest #2:

score: 76
Acceptable Answer
time: 2242ms
memory: 190144kb

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: 614ms
memory: 19688kb

input:

1000 1 499500 957319857

output:

Correct
7127326332295218295
1.000000
1331569654267968081

result:

points 1.0 Correct

Test #2:

score: 76
Acceptable Answer
time: 2243ms
memory: 189940kb

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