QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#292370#7118. Closing Timedanielkou58550 123ms44840kbC++173.8kb2023-12-28 02:45:232024-04-28 08:02:32

Judging History

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

  • [2024-04-28 08:02:32]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:123ms
  • 内存:44840kb
  • [2023-12-28 02:45:23]
  • 评测
  • 测评结果:0
  • 用时:123ms
  • 内存:44212kb
  • [2023-12-28 02:45:23]
  • 提交

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;
vector<int> parent;

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;
	// }

	parent[c] = p;

	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) {
	long long KOKC = K;
	
	adj.resize(N); psum1.resize(N); psum2.resize(N); NO1 = X, NO2 = Y; parent.resize(N);

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

	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> pq1, pq2;

	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (psum1[i] + psum2[i] == psum1[Y]) {
			ans++; status[i]++; K -= a[i];

			pq1.push({b[i] - a[i], i, 1});
		} else {
			pq1.push({a[i], i, 0});
			pq2.push({b[i], i, 0});
		}
	}

	// case for overlap
	while (true) {
		// suffer
		while (!pq1.empty() && (K < pq1.top()[0] || status[pq1.top()[1]] != pq1.top()[2])) {
			pq1.pop();
		}

		while (!pq2.empty() && (K < pq2.top()[0] || status[pq2.top()[1]] != pq2.top()[2])) {
			pq2.pop();
		}

		if (pq1.empty() && pq2.empty()) {
			break;
		}

		array<long long, 3> a1, a2, b1; a1[0] = a2[0] = b1[0] == (int) 1e18;

		// it wasn't cooking earlier but james said trust me so i trusted him
		if (!pq1.empty()) {
            a1 = pq1.top(); pq1.pop();

            status[a1[1]]++;

            while (!pq1.empty() && (K < pq1.top()[0] || status[pq1.top()[1]] != pq1.top()[2])) {
				pq1.pop();
			}
            
			status[a1[1]]--;

            if (!pq1.empty()) {
				a2 = pq1.top();
			}
        }

        if (!pq2.empty()) {
			b1 = pq2.top();
		}

		// actual shit
		if (pq2.empty() || a1[0] + a2[0] < b1[0]) {
			K -= a1[0]; ans++; status[a1[1]]++;
			
			// why casework
			if (status[a1[1]] == 1) {
				pq1.push({b[a1[1]] - a[a1[1]], a1[1], 1});
			}
		} else {
			// revert
			pq1.push(a1);

			K -= a[b1[1]];
			ans++; status[b1[1]]++;
			pq1.push({b[b1[1]] - a[a1[1]], a1[1], 1});
			pq2.pop();
		}
	}

	if (K < 0) {
		ans = 0; // fcuck
	}

	// cout << "fuck" << endl;

	// case 2: just choose everything
	vector<int> everything;

	for (int i = 0; i < N; i++) {
		everything.push_back(psum1[i]); everything.push_back(psum2[i]);
	}

	sort(all(everything));

	int ct1 = 0;

	for (int i = 0; i < 2 * N; i++) {
		if (KOKC - everything[i] >= 0) {
			KOKC -= everything[i]; ct1++;
		}
	}

	return max(ans, ct1);
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 123ms
memory: 44840kb

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
400000

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #4:

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

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
71

result:

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

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: 3808kb

input:

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

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
5

result:

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

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%