QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291946#7118. Closing Timedanielkou58550 86ms42044kbC++172.9kb2023-12-27 14:33:472024-04-28 08:00:52

Judging History

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

  • [2024-04-28 08:00:52]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:86ms
  • 内存:42044kb
  • [2023-12-27 14:33:47]
  • 评测
  • 测评结果:0
  • 用时:76ms
  • 内存:42940kb
  • [2023-12-27 14:33:47]
  • 提交

answer

// Source: https://usaco.guide/general/io

// #include "closing.h"
#include <bits/stdc++.h>

// #define int long long
#define double long double

#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define edge pair<int, int>

using namespace std;

vector<vector<edge>> adj;
vector<long long> psum1, psum2;

int NO1, NO2;

void genshit(int c, int p, int flag) {
	// if (p != -1 && flag == 0 && c == NO1) {
	// 	return;
	// }

	// if (p != -1 && flag == 1 && c == NO2) {
	// 	return;
	// }

	for (auto n : adj[c]) {
		if (n.first != p) {
			if (flag == 0) {
				psum1[n.first] = psum1[c] + n.second;
			} else {
				psum2[n.first] = psum2[c] + n.second;
			}

			genshit(n.first, c, flag);
		}
	}
}

struct cmp {
	bool operator()(const array<long long, 3> &x, const array<long long, 3> &y) const { 
		return x[0] > y[0];
	}
};

struct cmp2 {
	bool operator()(const array<long long, 3> &x, const array<long long, 3> &y) const { 
		return x[0] < y[0];
	}
};

int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
	adj.resize(N); psum1.resize(N); psum2.resize(N); NO1 = X, NO2 = Y;

	for (int i = 0; i < N; i++) {
		adj[i].clear(); psum1[i] = psum2[i] = 0LL;
	}

	for (int i = 0; i < N - 1; i++) {
		adj[U[i]].push_back({V[i], W[i]});
		adj[V[i]].push_back({U[i], W[i]});
	}

	// gen psum
	genshit(X, -1, 0); genshit(Y, -1, 1);

	// do the cardboard box thing
	vector<long long> a(N), b(N);

	for (int i = 0; i < N; i++) {
		a[i] = min(psum1[i], psum2[i]);
		b[i] = max(psum1[i], psum2[i]);

		// cout << psum1[i] << " " << psum2[i] << "\n";
		// cout << a[i] << " " << b[i] << "\n";
	}

	vector<int> status(N, 0); // 0 = nothing, 1 = one only, 2 = both

	// {cost, vertex, index}
	priority_queue<array<long long, 3>, vector<array<long long, 3>>, cmp> pq;

	vector<array<long long, 3>> trust;

	for (int i = 0; i < N; i++) {
		trust.push_back({a[i], i, 0});
	}

	int ans = 0; int ct = 0;
	
	sort(all(trust), cmp2());

	long long maxwt = 0;

	// cout << K << endl;

	while (ans <= K) {
		if (ct == N) {
			return ct;
		}

		if (ans + trust[ct][0] <= K) {
			// cout << trust[ct][1] << "\n";
			ans += trust[ct][0]; status[trust[ct][1]] = 1;
			pq.push({b[trust[ct][1]] - a[trust[ct][1]], trust[ct][1], 1}); maxwt = max(maxwt, trust[ct][0]); ct++; 
		} else {
			break;
		}
	}

	// cout << maxwt << "\n";

	// cout << ans << "\n";

	while (!pq.empty()) {
		auto t = pq.top(); pq.pop();

		bool fin = true;

		if (ans + t[0] <= K) {
			// check if all adj are activated
			// for (auto n : adj[t[1]]) {
			// 	if (!status[n.first]) { 
			// 		fin = false;
			// 	}
			// }

			if (t[0] + a[t[1]] <= K - maxwt) { // since we already chose the smaller one, only choose the bigger one if we can do that(greedy)
				// cout << t[0] << "\n";
				ans += t[0]; status[t[1]] = 2; ct++;
			}
		}
	}

	return ct;
}


详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 86ms
memory: 42044kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 31011 61157 8517583098
31011 129396 964383
1655 129396 331139
1655 191487 566483
110385 191487 865248
43212 110385 542661
43212 81682 13766
81682 91774 546589
91774 124706 780638
124706 175650 118706
10421 175650 615314
10421 151953 436270
140430 151...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
74937

result:

wrong answer 1st lines differ - on the 1st token, expected: '451', found: '74937'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 4072kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
50 23 25 382806473
0 1 375710
1 2 898637
2 3 10402
3 4 536577
4 5 385023
5 6 71075
6 7 543368
7 8 301497
8 9 174394
9 10 711312
10 11 923006
11 12 675532
12 13 838667
13 14 565729
14 15 979816
15 16 862618
16 17 576015
17 18 177751
18 19 306989
19 20 881492...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
50

result:

wrong answer 1st lines differ - on the 1st token, expected: '96', found: '50'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 0ms
memory: 3784kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 9
0 2 2
1 2 3
2 3 3

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
4

result:

wrong answer 1st lines differ - on the 1st token, expected: '6', found: '4'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%