QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#501942#8641. Ski 2green_gold_dog17 49ms231284kbC++202.9kb2024-08-03 00:05:202024-08-03 00:05:21

Judging History

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

  • [2024-08-03 00:05:21]
  • 评测
  • 测评结果:17
  • 用时:49ms
  • 内存:231284kb
  • [2024-08-03 00:05:20]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
bool assign_min(T& a, T b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
T square(T a) {
	return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
	ll operator() (pair<ll, ll> p) const {
		return ((__int128)p.first * MOD + p.second) % INF64;
	}
};

void solve() {
	ll n, k;
	cin >> n >> k;
	map<ll, vector<ll>> all;
	for (ll i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		all[x].push_back(y);
	}
	ll x = all.begin()->first;
	sort(all[x].begin(), all[x].end());
	ll cost = all[x][0];
	ll ans = (all[x].size() - 1) * k;
	for (ll i = 1; i < all[x].size(); i++) {
		all[x + 1].push_back(all[x][i]);
	}
	all.erase(x);
	ll nc = 0;
	vector<ll> aa;
	x++;
	while (nc > 0 || all.lower_bound(x) != all.end()) {
		aa.push_back(x);
		nc += all[x].size();
		if (nc <= 0) {
			ll y = all.lower_bound(x)->first;
			nc = 0;
			if (x == y) {
				y++;
			}
			x = y;
		} else {
			x++;
		}
		nc--;
	}
	aa.push_back(x);
	vector<vector<vector<ll>>> dp(aa.size(), vector<vector<ll>>(n + 1, vector<ll>(n + 1, INF64)));
	dp[0][0][1] = ans;
	ll mcp = 0, msz = 1;
	for (ll i = 0; i + 1 < aa.size(); i++) {
		sort(all[aa[i]].begin(), all[aa[i]].end());
		vector<ll> bests(msz + 1, INF64);
		for (ll cp = 0; cp <= mcp; cp++) {
			ll best = INF64;
			for (ll sz = msz; sz >= 1; sz--) {
				bool c = false;
				if (dp[i][cp][sz] >= best) {
					c = true;
				} else {
					best = dp[i][cp][sz];
				}
				if (dp[i][cp][sz] >= bests[sz]) {
					c = true;
				} else {
					bests[sz] = dp[i][cp][sz];
				}
				if (c) {
					continue;
				}
				ll ce = cp + all[aa[i]].size() - sz;
				for (ll addsz = 0; addsz <= max(0ll, ce); addsz++) {
					assign_min(dp[i + 1][max(0ll, ce - addsz)][sz + addsz], dp[i][cp][sz] + cost * addsz + max(0ll, ce - addsz) * k);
				}
			}
		}
		if (!all[aa[i]].empty()) {
			assign_min(cost, all[aa[i]][0]);
		}
		msz += all[aa[i]].size();
		mcp += all[aa[i]].size();
		mcp--;
		assign_max(mcp, 0ll);
	}
	ans = INF64;
	for (ll i = 0; i <= n; i++) {
		assign_min(ans, dp.back()[0][i]);
	}
	cout << ans << '\n';
}

int main() {
	if (IS_FILE) {
		freopen("", "r", stdin);
		freopen("", "w", stdout);
	}
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
	ll t = 1;
	if (IS_TEST_CASES) {
		cin >> t;
	}
	for (ll i = 0; i < t; i++) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 20ms
memory: 224148kb

input:

300 987761245
249 97
279 38
52 53
190 2
294 46
170 93
260 70
273 6
49 4
32 71
188 28
212 10
253 86
187 46
167 27
32 75
226 90
86 17
172 24
129 70
291 78
189 98
97 98
256 19
228 36
240 86
240 63
269 21
81 81
41 25
155 49
279 12
176 49
136 25
260 95
271 90
202 79
299 36
79 53
297 59
46 92
202 19
125 3...

output:

144

result:

ok single line: '144'

Test #2:

score: 5
Accepted
time: 19ms
memory: 226272kb

input:

300 451766134
225 3
78 77
144 26
211 37
119 39
126 65
7 47
53 7
121 37
52 60
212 24
168 60
212 42
104 45
218 4
146 42
234 25
43 83
126 67
128 61
125 80
87 62
113 8
71 28
148 80
175 34
126 77
295 91
35 62
265 31
35 29
108 8
195 34
85 59
250 41
78 62
242 17
178 80
34 15
187 60
94 34
50 25
144 29
10 8
...

output:

103

result:

ok single line: '103'

Test #3:

score: 5
Accepted
time: 27ms
memory: 224028kb

input:

300 584296612
252 63
248 8
136 92
181 38
206 77
229 21
196 84
7 86
187 29
170 42
195 10
148 100
279 2
113 65
22 18
148 68
11 14
187 72
133 59
205 7
155 95
251 76
300 18
265 19
76 59
59 76
86 7
73 84
101 49
19 47
25 70
24 44
29 75
112 77
128 27
28 27
198 29
148 56
128 89
218 26
177 13
117 84
25 91
0 ...

output:

1168593404

result:

ok single line: '1168593404'

Test #4:

score: 5
Accepted
time: 23ms
memory: 224068kb

input:

300 542226210
235 86
10 24
160 95
40 31
293 60
285 77
285 97
24 83
26 70
254 50
136 68
112 23
84 28
236 41
101 49
70 94
282 6
231 57
199 51
146 39
55 54
192 47
192 66
72 74
186 96
136 42
72 13
282 18
296 53
127 46
16 75
241 84
146 52
241 62
231 5
143 46
40 35
105 69
126 31
252 3
101 16
154 33
30 100...

output:

125

result:

ok single line: '125'

Test #5:

score: 5
Accepted
time: 28ms
memory: 231284kb

input:

300 851059749
59 76
266 2
7 58
202 53
214 58
256 30
99 28
224 16
64 80
150 93
12 14
278 15
196 7
259 97
13 27
256 100
66 90
257 26
85 44
49 64
171 63
266 37
95 44
123 75
203 41
261 89
81 30
65 51
64 42
66 45
108 10
198 45
128 86
234 49
199 77
65 37
234 52
246 8
198 12
50 3
181 71
218 83
66 85
261 73...

output:

851059869

result:

ok single line: '851059869'

Test #6:

score: 5
Accepted
time: 15ms
memory: 223236kb

input:

300 947403587
92 86
43 91
295 85
105 15
236 78
295 66
11 82
72 54
69 76
145 17
224 66
19 35
249 75
21 92
99 85
38 61
222 81
145 68
14 60
21 23
38 97
133 63
257 6
139 64
295 34
133 80
157 29
57 33
38 9
155 31
102 77
191 98
201 87
255 85
203 38
242 54
38 78
242 59
159 81
26 56
43 82
102 83
14 94
36 87...

output:

947404177

result:

ok single line: '947404177'

Test #7:

score: 5
Accepted
time: 49ms
memory: 219008kb

input:

300 363080349
19 96
23 83
20 86
22 86
7 93
12 100
21 79
14 92
15 90
19 91
23 96
16 89
20 84
8 100
22 79
21 94
20 85
19 88
11 100
22 90
22 80
2 99
23 89
21 84
23 80
8 96
9 96
23 88
17 93
16 84
11 95
22 90
18 86
11 92
19 81
18 88
9 92
12 97
4 98
17 89
23 95
5 99
10 93
18 89
10 97
16 91
8 97
16 85
20 8...

output:

363082396

result:

ok single line: '363082396'

Test #8:

score: 5
Accepted
time: 39ms
memory: 219004kb

input:

300 1000000000
300 57
300 24
300 40
300 45
300 68
300 38
300 94
300 79
300 39
300 87
300 98
300 79
300 63
300 56
300 97
300 63
300 52
300 61
300 83
300 35
300 19
300 38
300 12
300 9
300 87
300 3
300 92
300 54
300 5
300 37
300 43
300 11
300 25
300 87
300 70
300 65
300 58
300 57
300 70
300 87
300 67
3...

output:

299000000298

result:

ok single line: '299000000298'

Subtask #2:

score: 12
Accepted

Test #9:

score: 12
Accepted
time: 40ms
memory: 219064kb

input:

300 1
0 6596366
1 195480684
2 39457151
1 832234727
1 462764495
2 81049898
0 487070027
1 430671894
2 721333033
1 615885993
1 842070560
1 592116125
2 840818824
0 544935711
2 333187430
2 467111553
0 416912849
2 159079860
0 478546939
0 593053374
0 876528192
2 9215174
1 93255151
2 120891934
0 10339332
2 ...

output:

44543

result:

ok single line: '44543'

Test #10:

score: 12
Accepted
time: 39ms
memory: 218996kb

input:

300 1060203
0 1286878
1 960668502
2 190866228
1 195306795
1 233497287
0 343641186
0 693228127
0 67978764
2 598546069
0 751890541
0 37754998
0 305348452
1 266631431
1 844903768
1 560113131
2 47250552
0 594767495
2 809926081
0 586661105
0 366656127
0 589306393
2 416896948
2 89253046
1 363341342
0 9491...

output:

373039535

result:

ok single line: '373039535'

Test #11:

score: 12
Accepted
time: 40ms
memory: 219060kb

input:

300 1011700
0 4143879
5 61178231
1 214955252
5 577924292
3 532426729
4 862464334
4 215922747
1 602163591
2 90390184
4 709933135
1 948890772
3 784747556
2 261263945
4 784527448
3 989184114
5 465210434
3 83935742
5 876450661
3 626127035
1 699569645
1 5830291
4 974711739
0 542998610
3 604346813
1 14345...

output:

365657793

result:

ok single line: '365657793'

Test #12:

score: 12
Accepted
time: 39ms
memory: 218992kb

input:

300 2629882
0 7876717
1 380548027
4 210300855
3 804812637
0 795433451
0 696287735
1 251831535
2 510880579
5 328652705
0 850216531
5 609349591
3 66131892
5 355383071
2 846765095
2 127222407
1 933995931
0 609083290
4 506229752
1 922802380
3 277035017
2 693421958
0 339580672
4 296433175
1 933653265
2 5...

output:

732780332

result:

ok single line: '732780332'

Test #13:

score: 12
Accepted
time: 36ms
memory: 219024kb

input:

300 2161
0 4686752
8 629699716
36 412556162
10 196116733
93 237242586
45 458684505
60 125966325
2 855656971
76 750982211
88 543425907
38 355258329
92 448453464
26 608377947
93 18561617
69 644272241
23 178136181
48 306908918
32 962694105
79 683443776
28 623663382
100 501582180
92 578581062
26 8341942...

output:

10667943

result:

ok single line: '10667943'

Test #14:

score: 12
Accepted
time: 36ms
memory: 219184kb

input:

300 1264601
0 2244378
70 999535496
70 770638615
43 175588958
7 679253897
72 966146892
8 723807777
30 214248412
86 304229971
69 177589825
48 546447871
66 385401179
92 977036346
39 868966348
81 533340807
23 441268090
51 803400831
84 17907592
22 67033263
60 751134225
1 131600198
14 437904793
79 3453315...

output:

18239848

result:

ok single line: '18239848'

Test #15:

score: 12
Accepted
time: 8ms
memory: 223216kb

input:

300 425400
0 1915855
18 418792787
218 647548770
186 171684693
20 829774979
38 495244240
273 322971719
51 872137770
279 602534746
37 558726564
180 812007613
102 106188773
37 691630980
172 664413269
154 456050691
155 277923631
218 685494540
56 834990956
128 808406942
73 966781691
154 610439249
198 103...

output:

5958710

result:

ok single line: '5958710'

Test #16:

score: 12
Accepted
time: 27ms
memory: 222836kb

input:

300 1158451
1 12714371
194 740204971
274 273192348
10 233690292
30 152192819
241 350005285
140 376261817
105 246687825
290 515238843
15 563646519
47 417246070
244 220045148
155 413470747
204 711463900
167 810376102
185 470107777
271 261463098
232 228256857
108 164983349
59 752563934
109 787862089
11...

output:

31220997

result:

ok single line: '31220997'

Test #17:

score: 12
Accepted
time: 36ms
memory: 218996kb

input:

300 232014275
0 1335577
20 923253862
10 861996110
2 534287257
4 97575908
6 703656009
20 176840984
0 995189842
4 847450828
10 532473518
8 638980368
20 956596084
6 790434470
4 773069953
12 772814387
14 893619615
8 394660502
16 367410607
20 210732209
2 338176881
20 862071228
10 159569938
4 345386924
14...

output:

5617758949

result:

ok single line: '5617758949'

Test #18:

score: 12
Accepted
time: 40ms
memory: 219136kb

input:

300 7917929
2 23753787
4 881012995
4 843565653
6 243395540
6 332308712
6 731673552
8 768571347
8 667663560
8 999384285
8 605635849
10 672916805
10 549596745
10 608973816
10 969769288
10 123642168
12 924486873
12 714943281
12 322453474
12 611226720
12 70245389
12 249196857
14 43704099
14 400483309
14...

output:

522583314

result:

ok single line: '522583314'

Test #19:

score: 12
Accepted
time: 28ms
memory: 219080kb

input:

300 5712244
2 85683660
4 531574076
4 143856895
6 500019170
6 569021851
6 845915493
8 484912884
8 110335721
8 377454454
8 970107075
10 668551087
10 573840833
10 602084189
10 840330670
10 393762627
12 676568255
12 481846266
12 529475072
12 307726263
12 960271047
12 725995830
14 348984197
14 214766767
...

output:

1388075292

result:

ok single line: '1388075292'

Subtask #3:

score: 0
Wrong Answer

Test #20:

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

input:

10 849097758
4 937762392
10 817247459
0 440668594
1 912982987
7 663812156
7 594886472
0 837105766
2 737473115
3 649275922
10 873042888

output:

1289766352

result:

ok single line: '1289766352'

Test #21:

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

input:

10 9998
5 878445115
0 949971639
4 896709623
3 782518625
0 763551803
2 795919483
10 820305225
7 955019709
0 988957902
6 794013355

output:

89982

result:

ok single line: '89982'

Test #22:

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

input:

10 313931642
1 752682337
6 864853209
7 172291208
3 849996643
9 462903663
3 806832309
7 415016851
7 200488544
2 936575125
4 772486850

output:

1066613979

result:

ok single line: '1066613979'

Test #23:

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

input:

10 374
3 962058719
9 752701033
9 645570821
7 985449153
7 578273422
3 804266379
5 854354117
4 993866589
9 911208632
4 975880747

output:

5610

result:

ok single line: '5610'

Test #24:

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

input:

10 324770512
10 375908339
1 411213202
4 392519015
8 901521995
5 421608634
9 705664450
3 592078552
6 633681433
0 534389104
10 683380690

output:

392519015

result:

wrong answer 1st lines differ - expected: '324770512', found: '392519015'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

0%