QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#144885 | #4187. Decrypting Zodiac | OneWan | WA | 10ms | 37936kb | C++20 | 1.6kb | 2023-08-21 19:39:18 | 2023-08-21 19:39:21 |
Judging History
answer
// Problem: D - Excursion to Porvoo
// Contest: Virtual Judge - Namomo Summer Camp 23 Day 1
// URL: https://vjudge.net/contest/576636#problem/D
// Memory Limit: 2028 MB
// Time Limit: 3000 ms
#include <bits/stdc++.h>
using namespace std;
// 2023 OneWan
struct Node {
int i, d, c, idx;
Node() = default;
Node(int i, int d, int c, int idx) : i(i), d(d), c(c), idx(idx) {}
bool operator<(const Node &x) const {
if (d == x.d) {
return c < x.c;
}
return d > x.d;
}
};
priority_queue<Node> que[100005];
vector<int> pos[1000005];
bool vis[100005];
long long ans[1000005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<Node> edge(m + 1);
for (int i = 0 ; i < m ; i++) {
cin >> edge[i].i >> edge[i].d >> edge[i].c;
edge[i].idx = i;
que[edge[i].i].emplace(edge[i]);
pos[edge[i].c].emplace_back(i);
}
long long res = 0;
for (int i = 1 ; i < n ; i++) {
if (que[i].empty()) {
res = -1;
break;
} else {
Node p = que[i].top();
res += p.d;
}
}
for (int i = 1 ; i <= 1000000 ; i++) {
ans[i] = res;
if (res != -1) {
for (auto &v : pos[i]) {
Node p = edge[v];
vis[v] = true;
if (!que[p.i].empty()) {
res -= que[p.i].top().d;
}
while (!que[p.i].empty() && vis[que[p.i].top().idx]) {
que[p.i].pop();
}
if (!que[p.i].empty()) {
res += que[p.i].top().d;
} else {
res = -1;
}
}
}
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
if (ans[x] == -1) cout << "impossible\n";
else cout << ans[x] << "\n";
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 10ms
memory: 37936kb
input:
6 drhmex zodiac
output:
0 0 0
result:
wrong answer 1st lines differ - expected: '2', found: '0'