QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#292043#7118. Closing Timehypeskynick0 123ms43304kbC++142.8kb2023-12-27 16:31:522024-04-28 08:01:33

Judging History

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

  • [2024-04-28 08:01:33]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:123ms
  • 内存:43304kb
  • [2023-12-27 16:31:52]
  • 评测
  • 测评结果:0
  • 用时:135ms
  • 内存:43644kb
  • [2023-12-27 16:31:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp push
vector<vector<pair<int,ll>>> graph;
vector<bool> vis;
vector<ll> seg1,seg2;

struct node {
	ll t;
	int x, cnt = 0;
	bool operator<(const node &b) const {
        return t < b.t;
    }
    bool operator>(const node &b) const {
        return b < (*this);
    }
};

void ddd(vector<ll>& cseg, int node, ll dist) {
	vis[node] = true;
	cseg[node] = dist;
	for (auto [c, w] : graph[node]) {
		if (!vis[c]) {
			ddd(cseg, c, dist + w);
		}
	}
}

int greedy(int mx, ll k, ll mdist) {
	int N = graph.size(), ans = 0;
	vector<int> cnt(N, 0);
	priority_queue<node, vector<node>, greater<node>> pqa, pqb;

	for (int i = 0; i < N-1; i++) {
		if (mx == 2 && seg1[i] + seg2[i] == mdist) {
			ans++;
			cnt[i]++;
			k -= min(seg1[i], seg2[i]);
            pqa.pp({abs(seg1[i] - seg2[i]), i, 1});
		} else {
			pqa.pp({min(seg1[i], seg2[i]), i ,0});
			if (mx == 2) {
				pqb.pp({max(seg1[i], seg2[i]), i , 0});
			}
		}
	}

	auto get_top = [](priority_queue<node, vector<node>, greater<node>>& pq) -> node {
        return pq.empty() ? node{(ll)1e18, 0} : pq.top();
    };

    auto reduce = [&cnt, &mx, &k](priority_queue<node, vector<node>, greater<node>>& pq) -> void {
        while (!pq.empty() && (cnt[pq.top().x] != pq.top().cnt || k < pq.top().t)) {
            pq.pop();
        }
    };

    while (!pqa.empty() || !pqb.empty()) {
        reduce(pqa);
        reduce(pqb);
        if (pqa.empty() && pqb.empty())
            break;
        node one1 = get_top(pqa), one2;
        if (!pqa.empty()) {
            pqa.pop();
            cnt[one1.x]++;
            reduce(pqa);
            cnt[one1.x]--;
            one2 = get_top(pqa);
        }
        node two = get_top(pqb);
        if (pqb.empty() || one1.t + one2.t < two.t) {
            k -= one1.t;
            ans++;
            cnt[one1.x]++;
            if (mx == 2 && cnt[one1.x] == 1) {
                pqa.pp({abs(seg1[one1.x] - seg2[one1.x]), one1.x, 1});
            }
        } else {
            pqa.pp(one1);
            k -= min(seg1[two.x], seg2[two.x]);
            ans++;
            cnt[two.x]++;
            pqa.pp({abs(seg1[two.x] - seg2[two.x]), two.x, 1});
            pqb.pop();
        }
    }
    return k < 0 ? 0 : ans;
}

int max_score(int N, int X, int Y, ll k, vector<int> U, vector<int> V, vector<int> W) {
    graph.assign(N , vector<pair<int, ll>>());
	vis.assign(N , false);
	seg1.assign(N , 0);
	seg2.assign(N , 0);

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

	ddd(seg1, X, 0);
	vis.assign(N, false);
	ddd(seg2, Y, 0);

    return max(greedy(2, k, seg1[Y]), greedy(1, k, seg1[Y]));
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 8
Accepted
time: 123ms
memory: 42244kb

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
451

result:

ok 

Test #2:

score: 8
Accepted
time: 119ms
memory: 43304kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 97133 170892 35489415917
114511 170892 730058
34783 114511 435023
34783 47301 562314
47301 162600 457629
44856 162600 365133
44856 133801 83016
117539 133801 124222
117539 128719 199821
77871 128719 703141
77871 133155 624331
7211 133155 138691
7211 ...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
650

result:

ok 

Test #3:

score: 0
Wrong Answer
time: 55ms
memory: 6584kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
200
1000 611 992 5736784
504 611 954658
504 936 219278
502 936 632439
393 502 177662
267 393 570266
267 291 941365
291 310 168052
310 765 253098
635 765 724932
274 635 842125
274 799 848645
39 799 433118
39 940 705598
553 940 564063
553 960 69665
917 960 6904...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
126
38
69
34
52
33
42
32
39
41
38
36
45
84
40
44
50
42
47
34
37
47
38
37
39
37
44
39
32
33
38
54
25
36
46
33
37
35
28
36
45
43
44
49
37
33
43
44
53
42
33
30
50
41
37
40
37
44
207
31
37
45
36
43
35
40
41
39
135
53
40
32
31
37
34
38
51
48
36
40
48
42
43
43
3...

result:

wrong answer 21st lines differ - on the 1st token, expected: '38', found: '37'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 9
Accepted
time: 0ms
memory: 4076kb

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
96

result:

ok 

Test #5:

score: 9
Accepted
time: 0ms
memory: 3824kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
47 20 22 25669694
0 1 291237
1 2 851987
2 3 421247
3 4 962919
4 5 643085
5 6 224951
6 7 756890
7 8 147295
8 9 625823
9 10 736374
10 11 290526
11 12 335466
12 13 539086
13 14 957449
14 15 423408
15 16 932444
16 17 356032
17 18 307118
18 19 94279
19 20 989546...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
26

result:

ok 

Test #6:

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

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
46 6 34 355277954
0 1 574359
1 2 58362
2 3 778155
3 4 538832
4 5 128903
5 6 79774
6 7 715282
7 8 259924
8 9 640303
9 10 361135
10 11 506866
11 12 527045
12 13 946672
13 14 620381
14 15 701743
15 16 766266
16 17 524732
17 18 340089
18 19 630172
19 20 357712
...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
73

result:

wrong answer 1st lines differ - on the 1st token, expected: '74', found: '73'

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

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%