QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114449 | #4583. Concerto de Pandemic | berarchegas# | WA | 191ms | 142768kb | C++17 | 3.6kb | 2023-06-22 04:08:44 | 2023-06-22 04:08:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int INF = 2e9;
ll tempo[MAXN], f[MAXN], fan[MAXN], need[MAXN], id[MAXN], ant[MAXN], to[20][MAXN], bbto[20][MAXN];
ll esq[MAXN], dir[MAXN], cost[20][MAXN], bbcost[20][MAXN], ed[MAXN], costEd[MAXN];
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt", "r", stdin);
int n, m, k, p, a, b;
cin >> n >> m >> k >> p;
for (int i = 0; i < m; i++) {
cin >> a >> b;
tempo[a] = b;
}
for (int i = 0; i < k; i++) {
cin >> a;
f[a] = 1;
}
if (p >= k) {
cout << "0\n";
return 0;
}
int lst = 0;
ll sum = 0;
for (int i = 1; i <= 2 * n; i++) {
if (i <= n && !tempo[i]) {
dir[lst++] = sum + 1;
sum = 0;
}
else if (i > n && !tempo[i - n]) {
dir[lst++] = sum + 1;
sum = 0;
break;
}
else {
if (i > n)
sum += tempo[i - n] + 1;
else
sum += tempo[i] + 1;
}
}
ll at = 1, mx = 0;
for (int i = 1; i <= n; i++) {
if (!tempo[i]) {
if (f[i]) {
fan[at] = 1;
mx = at;
}
at++;
}
}
// 1 ate qtd
int qtd = lst - 1;
for (int i = 1; i <= qtd; i++) {
ant[i] = mx;
if (fan[i]) mx = i;
}
for (int i = 1; i <= qtd; i++) {
if (ant[i] < i) {
need[i] = qtd - i + ant[i] + 1;
}
else {
need[i] = ant[i] - i + 1;
}
}
for (int i = 1; i <= qtd; i++) {
to[0][i] = i % qtd + 1;
cost[0][i] = dir[i];
}
for (int i = 1; i < 20; i++) {
for (int j = 1; j <= qtd; j++) {
to[i][j] = to[i - 1][to[i - 1][j]];
cost[i][j] = cost[i - 1][j] + cost[i - 1][to[i - 1][j]];
}
}
ll l = 0, r = 2e10;
while (r > l + 1) {
ll m = (l + r) / 2;
// calculate bbto e bbcost
for (int i = 1; i <= qtd; i++) {
ll anda = 0, custo = 0, at = i;
for (int j = 19; j >= 0; j--) {
if (custo + cost[j][at] <= m) {
custo += cost[j][at];
at = to[j][at];
anda += (1 << j);
}
}
costEd[i] = anda;
ed[i] = at;
}
for (int i = 1; i <= qtd; i++) {
bbto[0][i] = ed[ed[i]] % qtd + 1;
bbcost[0][i] = costEd[i] + costEd[ed[i]] + 1;
}
for (int i = 1; i < 20; i++) {
for (int j = 1; j <= qtd; j++) {
bbto[i][j] = bbto[i - 1][bbto[i - 1][j]];
bbcost[i][j] = bbcost[i - 1][j] + bbcost[i - 1][bbto[i - 1][j]];
}
}
// menor numero de shows se comecarmos em i
bool ok = false;
for (int i = 1; i <= qtd; i++) {
ll at = i, caras = 0;
for (int j = 19; j >= 0; j--) {
if (p & (1 << j)) {
caras += bbcost[j][at];
at = bbto[j][at];
}
}
ok |= caras >= need[i];
}
if (ok) r = m;
else l = m;
}
cout << r << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 138696kb
input:
10 4 3 2 1 2 4 4 6 2 7 5 2 5 8
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7560kb
input:
8 1 3 5 1 5 4 2 7
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 142768kb
input:
5 2 2 1 1 14 2 14 3 5
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5500kb
input:
2 1 1 1 1 200000 2
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 191ms
memory: 141752kb
input:
190976 113222 55610 23475 51263 120558 10007 171596 46671 108981 117183 169457 18187 84735 149298 124718 79376 129184 28117 76880 109791 87521 114840 59510 38014 178362 41701 11344 27561 192741 173835 54534 71368 76692 122745 95537 152595 158352 43901 162441 98927 105784 22484 96000 19443 113614 370...
output:
196914
result:
wrong answer 1st lines differ - expected: '170531', found: '196914'