QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#144885#4187. Decrypting ZodiacOneWanWA 10ms37936kbC++201.6kb2023-08-21 19:39:182023-08-21 19:39:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-21 19:39:21]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:37936kb
  • [2023-08-21 19:39:18]
  • 提交

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'