QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185208 | #4188. Excursion to Porvoo | rgnerdplayer# | WA | 41ms | 5912kb | C++20 | 1.5kb | 2023-09-21 19:05:01 | 2023-09-21 19:05:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
auto solve = [&]() {
int n, m;
cin >> n >> m;
vector<array<int, 3>> e(m);
for (auto &[c, d, u] : e) {
cin >> u >> d >> c;
u--;
}
sort(e.begin(), e.end());
int q;
cin >> q;
vector<array<int, 2>> qs(q);
for (int i = 0; i < q; i++) {
cin >> qs[i][0];
qs[i][1] = i;
}
sort(e.rbegin(), e.rend());
sort(qs.rbegin(), qs.rend());
constexpr int INF = 2e4;
vector<int> mn(n - 1, INF);
int cnt = n - 1;
int sum = (n - 1) * INF;
vector<int> ans(q, sum);
for (int j = 0; auto [v, i] : qs) {
while (j < m && e[j][0] >= v) {
auto [c, d, u] = e[j];
if (d < mn[u]) {
if (mn[u] == INF) {
cnt--;
}
sum -= mn[u] - d;
mn[u] = d;
}
j++;
}
if (cnt == 0) {
ans[i] = sum;
}
}
for (int i = 0; i < q; i++) {
if (ans[i] == INF) {
cout << "impossible\n";
} else {
cout << ans[i] << '\n';
}
}
};
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
2 2 1 100 300 1 1 30 5 400 500 300 20 1
output:
impossible impossible 100 1 1
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
5 7 1 200 30 2 200 31 3 200 32 4 200 33 1 5000 33 2 5000 33 3 5000 33 3 30 31 33
output:
800 5600 15200
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
2 3 1 3 3 1 4 2 1 2 1 3 1 3 2
output:
2 3 3
result:
ok 3 lines
Test #4:
score: -100
Wrong Answer
time: 41ms
memory: 5912kb
input:
100000 99999 1 8793 670998 2 3301 949483 3 5662 542705 4 3033 907487 5 7035 366434 6 5771 1750 7 2575 80336 8 5163 613257 9 5748 414726 10 4990 119039 11 5855 239538 12 1965 755221 13 8891 149341 14 3213 674329 15 9189 660274 16 4593 513364 17 793 326875 18 2873 954337 19 3470 105349 20 9374 779965 ...
output:
1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 1999980000 199...
result:
wrong answer 1st lines differ - expected: 'impossible', found: '1999980000'