QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515717 | #4374. What Really Happened on Mars? | karuna | WA | 1ms | 3844kb | C++20 | 3.2kb | 2024-08-11 21:53:16 | 2024-08-11 21:53:17 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int SZ = 30;
int n, r, occ[SZ], rnk[SZ], pr[SZ], st[SZ], ans[SZ], has[SZ], sp[SZ];
vector<pii> C[SZ];
vector<int> G[SZ];
int vis[SZ], cur[SZ];
int dfs(int v) {
vis[v] = true;
int ret = cur[v];
for (int x : G[v]) {
if (!vis[x]) {
ret = max(ret, dfs(x));
}
}
return ret;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> r;
for (int i = 1; i <= n; i++) {
cin >> st[i] >> pr[i];
int sz;
cin >> sz;
for (int j = 0; j < sz; j++) {
string S;
cin >> S;
char c = S[0];
int num = stoi(S.substr(1));
if (c == 'C') {
while (num--) C[i].push_back({0, 1});
}
if (c == 'L') C[i].push_back({1, num});
if (c == 'U') C[i].push_back({2, num});
}
}
for (int i = 1; i <= n; i++) {
for (auto [t, x] : C[i]) if (t == 1) rnk[x] = max(rnk[x], pr[i]);
}
int t = 0;
while (true) {
fill(cur, cur + n + 1, 0);
int yes[n + 1]{};
bool flag = false;
for (int i = 1; i <= n; i++) {
if (st[i] <= t && sp[i] < C[i].size()) yes[i] = true;
if (sp[i] < C[i].size()) flag = true;
}
if (!flag) break;
for (int i = 1; i <= n; i++) G[i].clear();
for (int i = 1; i <= n; i++) if (yes[i]) {
cur[i] = pr[i];
if (C[i][sp[i]].ff == 1 && occ[C[i][sp[i]].ss]) {
G[occ[C[i][sp[i]].ss]].push_back(i);
yes[i] = false;
}
}
for (int i = 1; i <= n; i++) {
if (yes[i]) cur[i] = max(cur[i], dfs(i));
fill(vis + 1, vis + 1 + n, 0);
}
int k = -1, elt;
for (int i = 1; i <= r; i++) if (occ[i] && (k == -1 || rnk[i] > rnk[k])) {
k = i;
elt = occ[i];
}
if (k != -1) {
int block[n + 1]{};
int maxv = 0;
for (int i = 1; i <= n; i++) if (yes[i] && C[i][sp[i]].ff == 1) {
if (cur[i] <= rnk[k] && i != elt) {
block[i] = true;
maxv = max(maxv, cur[i]);
}
}
for (int i = 1; i <= n; i++) if (yes[i] && !block[i]) {
if (has[i]) cur[i] = max(cur[i], maxv);
}
for (int i = 1; i <= n; i++) if (block[i]) yes[i] = false;
}
int at = -1;
for (int i = 1; i <= n; i++) if (yes[i] && (at == -1 || cur[at] < cur[i])) at = i;
if (at == -1) {
++t;
continue;
}
auto [type, x] = C[at][sp[at]++];
if (type == 0) {
ans[at] = t + x;
t += x;
}
else if (type == 1) {
occ[x] = at;
ans[at] = t;
has[at]++;
}
else if (type == 2) {
occ[x] = 0;
ans[at] = t;
has[at]--;
}
}
for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
3 1 50 2 5 C1 L1 C1 U1 C1 1 1 5 C1 L1 C100 U1 C1 70 3 1 C1
output:
106 107 71
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 3 5 3 5 C1 L1 C1 U1 C1 3 2 9 C1 L2 C1 L3 C1 U3 C1 U2 C1 1 1 9 C1 L3 C3 L2 C1 U2 C1 U3 C1
output:
8 15 16
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
19 8 7 7 23 L8 C5 C1 C1 L1 U1 L5 L3 U3 U5 U8 C1 C4 L3 L1 C2 U1 U3 L3 C2 C4 U3 C2 19 14 6 L7 L3 L4 U4 U3 U7 6 5 3 L1 U1 C5 35 2 18 L2 L5 L7 U7 C3 C3 C3 U5 U2 L4 L1 C2 C2 C5 U1 U4 L3 U3 45 6 3 C3 L6 U6 32 3 10 C4 C1 C3 L1 L6 L8 C2 U8 U6 U1 17 17 50 L4 L6 C4 L8 U8 U6 U4 L1 L5 L2 L8 L4 L3 L7 L6 U6 U7 U3...
output:
329 136 337 379 332 361 106 307 1 251 285 209 419 59 136 201 351 114 57
result:
ok 19 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
15 6 35 14 45 L2 L6 L3 L5 L1 L4 C2 C5 C1 C1 C4 C5 C4 C1 C4 C4 C1 C1 C3 C4 C4 C2 C2 C5 C2 C5 C3 C5 C2 C2 C5 C5 C2 C4 U4 U1 U5 U3 U6 L6 C3 L3 U3 U6 U2 3 7 17 L4 U4 L6 L3 L1 C2 U1 C5 U3 U6 L3 L4 L5 U5 C2 U4 U3 32 13 19 L1 L3 L5 C5 U5 U3 L2 L4 C2 U4 U2 L3 C5 C4 L5 U5 C4 U3 U1 18 4 44 L2 L5 L4 L3 L6 L1 C...
output:
130 12 150 382 127 289 247 253 218 175 414 218 197 417 487
result:
ok 15 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
20 1 42 1 34 C1 L1 C5 C3 C5 C1 C3 U1 L1 C4 C2 C2 C3 C1 C1 C1 U1 C3 C3 C3 L1 C4 C5 C2 U1 C1 C1 L1 C2 C5 U1 C2 C3 C4 5 11 20 C3 L1 U1 L1 C1 C5 C4 C2 C4 C1 C3 C1 C4 C4 C2 C3 C4 C5 C3 U1 40 6 21 L1 C5 C3 C5 C1 C2 C3 C2 C5 C4 C4 C2 C4 C4 C5 C3 C4 C3 C1 C1 U1 45 16 43 L1 C2 C3 C2 C5 C3 C4 C2 C1 C1 C2 C1 C...
output:
1757 923 1361 547 747 444 172 554 1257 1300 1023 1582 1157 423 1471 874 320 129 653 1687
result:
ok 20 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
20 3 37 18 29 L2 C1 L3 L1 C4 C5 C4 C2 U1 U3 U2 C4 C2 L1 L3 L2 C1 C1 C2 C3 C5 C3 C3 C3 C4 C4 U2 U3 U1 3 1 32 L1 L2 L3 C1 C2 C5 C3 C4 C3 C4 C5 C4 C4 C1 C1 C3 C1 C2 U3 L3 C5 C3 C5 C2 C4 C2 C3 C5 U3 U2 U1 C5 34 13 14 C1 L2 L3 C3 C1 C4 C4 C2 L1 C1 C3 U1 U3 U2 42 9 43 L2 L1 L3 C4 C4 U3 L3 C2 C2 C4 C3 C4 U...
output:
156 991 461 698 490 703 105 98 610 922 383 986 558 442 781 362 243 765 786 885
result:
ok 20 lines
Test #7:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
19 8 29 10 9 L6 L5 L8 L3 C4 U3 U8 U5 U6 30 9 14 L2 L5 L7 L1 C5 C3 U1 C3 U7 C1 C4 C2 U5 U2 20 7 44 L6 C4 L2 U2 U6 L4 C5 U4 L1 U1 L3 L4 C5 C2 U4 C5 L7 L1 L6 L2 C4 U2 U6 U1 U7 L8 U8 L8 U8 L6 C3 U6 C2 C2 L2 C3 U2 C1 L1 U1 C1 U3 L5 U5 46 12 39 L2 L5 L1 L4 L7 C3 U7 U4 U1 L8 C5 C1 U8 L1 C5 C2 C5 L3 L4 C3 L...
output:
190 208 284 186 58 359 344 71 39 63 387 147 247 71 9 115 39 307 298
result:
ok 19 lines
Test #8:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
18 5 36 8 23 L5 L1 L4 L2 L3 C3 C5 U3 U2 L2 C4 L3 U3 C5 L3 U3 U2 L2 C2 U2 U4 U1 U5 44 5 30 L2 C3 C1 L4 U4 C4 C5 U2 L4 U4 C5 L5 C3 L1 U1 C5 C4 C5 L1 U1 U5 L1 L5 C3 U5 U1 C2 L4 U4 C5 38 15 44 L2 C5 C3 U2 C1 L5 C4 U5 C2 C2 L2 C5 C4 C4 L1 L5 L3 C5 U3 C4 C5 L3 U3 L4 U4 L4 U4 C3 U5 U1 L1 L5 C1 C1 C4 U5 L3 ...
output:
266 400 146 154 469 236 404 35 28 355 446 287 214 174 78 196 80 247
result:
ok 18 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
13 4 3 8 3 L2 C5 U2 39 9 29 L3 C5 C2 U3 L3 L2 U2 U3 C5 C4 C1 L2 L3 C5 L1 C5 L4 C4 U4 U1 U3 U2 L1 C3 C5 U1 C3 C5 C4 17 11 32 C4 L4 U4 L2 L3 L1 L4 U4 U1 U3 U2 L1 L4 U4 U1 L1 L4 U4 L2 U2 C5 C3 C1 L4 U4 L3 C1 C3 U3 U1 C4 C5 27 2 18 L2 L4 C3 C2 C2 L1 C5 U1 U4 U2 L3 L4 L2 L1 U1 U2 U4 U3 12 13 16 L1 L2 U2 ...
output:
8 125 43 479 17 518 365 302 74 201 467 163 1
result:
ok 13 lines
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 3616kb
input:
18 10 18 7 8 L10 L7 L5 U5 U7 U10 L1 U1 18 12 48 L3 L9 U9 U3 C3 L8 L1 L5 C5 C5 U5 U1 U8 C1 C2 L2 C3 C3 L7 C1 C2 U7 U2 L4 L6 U6 L2 L6 L5 L7 L9 L3 C5 U3 U9 U7 U5 U6 U2 U4 L3 L2 L4 L10 U10 U4 U2 U3 26 14 15 L8 U8 L10 C2 C2 C2 U10 L6 L4 C3 L7 C2 U7 U4 U6 41 9 4 L1 C3 C5 U1 28 11 33 L5 L9 C2 U9 U5 C1 C5 C...
output:
353 227 171 308 263 412 52 400 353 300 381 166 113 23 79 200 455 412
result:
wrong answer 7th lines differ - expected: '50', found: '52'