QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188580 | #7228. Random Points on the Circle | ucup-team004 | AC ✓ | 761ms | 34488kb | C++20 | 3.0kb | 2023-09-26 02:22:37 | 2023-09-26 02:22:38 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int L = 1 << 30;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::cin >> n >> k;
int seed, add;
std::cin >> seed >> add;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
seed = (1LL * seed * 239017 + add) % L;
a[i] = seed;
}
std::sort(a.begin(), a.end());
if (n >= 100) {
a.resize(2 * n);
for (int i = 0; i < n; i++) {
a[n + i] = a[i] + L;
}
std::vector<i64> pre(2 * n + 1);
for (int i = 0; i < 2 * n; i++) {
pre[i + 1] = pre[i] + a[i];
}
auto get = [&](int l, int r) {
int m = (l + r - 1) / 2;
i64 res = 0;
res += 1LL * a[m] * (m - l) - (pre[m] - pre[l]);
res += (pre[r] - pre[m]) - 1LL * a[m] * (r - m);
return res;
};
auto ans = *std::ranges::partition_point(std::ranges::iota_view(0LL, i64(1E18)),
[&](i64 x) {
std::vector<int> mx(2 * n);
for (int i = 0, j = 0; i < 2 * n; i++) {
while (j < 2 * n && get(i, j + 1) <= x) {
j++;
}
mx[i] = j;
}
for (int i = 0; i < 2 * n / k; i++) {
int v = i;
for (int j = 0; j < k; j++) {
v = mx[v];
if (v >= i + n) {
return false;
}
}
}
return true;
});
std::cout << ans << "\n";
return 0;
}
std::vector f(n, std::vector<i64>(n + 1));
for (int i = 0; i < n; i++) {
for (int j = 1; j <= n; j++) {
f[i][j] = 1E18;
for (int x = 0; x < j; x++) {
i64 res = 0;
for (int y = 0; y < j; y++) {
int d = std::abs(a[(i + x) % n] - a[(i + y) % n]);
res += std::min(d, L - d);
}
f[i][j] = std::min(f[i][j], res);
}
}
}
auto ans = *std::ranges::partition_point(std::ranges::iota_view(0LL, i64(1E18)),
[&](i64 x) {
bool ok = false;
for (int i = 0; i < n; i++) {
if (!ok) {
int l = 0;
int v = 0;
while (l < n) {
int r = l;
while (r < n && f[(i + l) % n][r + 1 - l] <= x) {
r++;
}
l = r;
v++;
}
if (v <= k) {
ok = true;
}
}
}
return !ok;
});
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3468kb
input:
10 2 13 123
output:
626098570
result:
ok 1 number(s): "626098570"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
10 3 13 123
output:
302532222
result:
ok 1 number(s): "302532222"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
10 10 13 123
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
10 3 363606310 110949573
output:
322659618
result:
ok 1 number(s): "322659618"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
10 4 781726900 293540865
output:
180377100
result:
ok 1 number(s): "180377100"
Test #6:
score: 0
Accepted
time: 62ms
memory: 3520kb
input:
99 1 631536274 125123859
output:
25113339950
result:
ok 1 number(s): "25113339950"
Test #7:
score: 0
Accepted
time: 62ms
memory: 3632kb
input:
99 98 986776257 679440378
output:
10208
result:
ok 1 number(s): "10208"
Test #8:
score: 0
Accepted
time: 62ms
memory: 3528kb
input:
99 2 773705026 882748599
output:
6078581409
result:
ok 1 number(s): "6078581409"
Test #9:
score: 0
Accepted
time: 62ms
memory: 3516kb
input:
99 97 1066064403 735048522
output:
203934
result:
ok 1 number(s): "203934"
Test #10:
score: 0
Accepted
time: 61ms
memory: 3620kb
input:
99 3 790112566 236340147
output:
2661879431
result:
ok 1 number(s): "2661879431"
Test #11:
score: 0
Accepted
time: 62ms
memory: 3520kb
input:
99 96 1019591337 460365297
output:
440848
result:
ok 1 number(s): "440848"
Test #12:
score: 0
Accepted
time: 61ms
memory: 3548kb
input:
99 4 680758893 333382150
output:
1639918184
result:
ok 1 number(s): "1639918184"
Test #13:
score: 0
Accepted
time: 62ms
memory: 3620kb
input:
99 95 847357058 929132527
output:
358904
result:
ok 1 number(s): "358904"
Test #14:
score: 0
Accepted
time: 61ms
memory: 3588kb
input:
99 5 445644008 100132784
output:
988115184
result:
ok 1 number(s): "988115184"
Test #15:
score: 0
Accepted
time: 62ms
memory: 3548kb
input:
99 94 549361567 1067608389
output:
555789
result:
ok 1 number(s): "555789"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
100 10 84767911 610333873
output:
251560975
result:
ok 1 number(s): "251560975"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1000 20 125604864 875792882
output:
663038720
result:
ok 1 number(s): "663038720"
Test #18:
score: 0
Accepted
time: 6ms
memory: 3624kb
input:
10000 10 671872425 790243593
output:
26718917867
result:
ok 1 number(s): "26718917867"
Test #19:
score: 0
Accepted
time: 7ms
memory: 3732kb
input:
10000 1000 649828772 353686006
output:
2742818
result:
ok 1 number(s): "2742818"
Test #20:
score: 0
Accepted
time: 3ms
memory: 3656kb
input:
10000 100 59473904 639861945
output:
267422367
result:
ok 1 number(s): "267422367"
Test #21:
score: 0
Accepted
time: 49ms
memory: 6004kb
input:
90000 10 1048291468 575029585
output:
241373453371
result:
ok 1 number(s): "241373453371"
Test #22:
score: 0
Accepted
time: 76ms
memory: 6076kb
input:
90000 9000 395055994 159188928
output:
306880
result:
ok 1 number(s): "306880"
Test #23:
score: 0
Accepted
time: 59ms
memory: 5984kb
input:
90000 300 247251128 466081796
output:
268548412
result:
ok 1 number(s): "268548412"
Test #24:
score: 0
Accepted
time: 196ms
memory: 14304kb
input:
360000 10 604876871 421966366
output:
965575496520
result:
ok 1 number(s): "965575496520"
Test #25:
score: 0
Accepted
time: 273ms
memory: 14388kb
input:
360000 36000 394191400 26842638
output:
76746
result:
ok 1 number(s): "76746"
Test #26:
score: 0
Accepted
time: 244ms
memory: 14316kb
input:
360000 600 688936536 354452435
output:
268440900
result:
ok 1 number(s): "268440900"
Test #27:
score: 0
Accepted
time: 564ms
memory: 34348kb
input:
1000000 10 415370459 331053934
output:
2680952049370
result:
ok 1 number(s): "2680952049370"
Test #28:
score: 0
Accepted
time: 756ms
memory: 34328kb
input:
1000000 100000 647234990 1030388958
output:
27624
result:
ok 1 number(s): "27624"
Test #29:
score: 0
Accepted
time: 752ms
memory: 34488kb
input:
1000000 1000 310788306 304973862
output:
268375390
result:
ok 1 number(s): "268375390"
Test #30:
score: 0
Accepted
time: 527ms
memory: 34344kb
input:
1000000 10 479772231 302292290
output:
2682252899276
result:
ok 1 number(s): "2682252899276"
Test #31:
score: 0
Accepted
time: 761ms
memory: 34484kb
input:
1000000 100000 80444941 1022344244
output:
27644
result:
ok 1 number(s): "27644"
Test #32:
score: 0
Accepted
time: 738ms
memory: 34480kb
input:
1000000 1000 186548259 317646077
output:
268389414
result:
ok 1 number(s): "268389414"