QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#330065#7812. 旅游巴士WRuperD100 ✓73ms12852kbC++141.6kb2024-02-17 11:37:032024-02-17 11:37:04

Judging History

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

  • [2024-02-17 11:37:04]
  • 评测
  • 测评结果:100
  • 用时:73ms
  • 内存:12852kb
  • [2024-02-17 11:37:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
int read(){int x = 0, f = 1;char ch = getchar(); while(ch < '0' or ch > '9'){if(ch == '-'){f = -1;} ch = getchar();} while(ch >= '0' and ch <= '9'){x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}return x * f;}
void write(int x){if(x < 0)	putchar('-'), x = -x;if(x >= 10)	write(x / 10);putchar(x % 10 + '0');}
#define put() putchar(' ')
#define endl puts("")
#define pb emplace_back
const int MAX = 1e4 + 10;

struct node{
	int v, w;
}; vector <node> g[MAX];

int f[MAX][105];

struct edge{
	int from, val, modd;
	bool operator < (const edge &x) const{
		return val > x.val;
	}
};

void dji(int u, int k, int n){
	priority_queue <edge> que;
	que.push(edge{1, 0, 0});
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= 104; j++){
			f[i][j] = mininf;
		}
	}
	f[1][0] = 0;
	while(!que.empty()){
		int u = que.top().from, val = que.top().val, modd = que.top().modd;
		que.pop();
		if(f[u][modd] != val)	continue;
		for(auto V : g[u]){
			int v = V.v, w = V.w;
			int cost = val + 1;
			if(w > val){
				cost = val + (w - val + k - 1) / k * k + 1;
			}
			if(f[v][(modd + 1) % k] > cost){
				f[v][(modd + 1) % k] = cost;
				que.push(edge{v, cost, (modd + 1) % k});
			}
		}
	}
	if(f[n][0] >= mininf)	puts("-1");
	else write(f[n][0]), endl;
}

void solve(){
	int n = read(), m = read(), k = read();
	for(int i = 1; i <= m; i++){
		int u = read(), v = read(), w = read();
		g[u].pb(node{v, w});
	}
	dji(1, k, n);
}

signed main(){
	int t = 1;
	while(t--)	solve();
	return 0;
}

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 3844kb

input:

9 14 95
7 9 0
6 9 0
4 2 0
3 4 0
5 7 0
7 9 0
8 7 0
5 3 0
8 7 0
1 6 0
5 3 0
2 8 0
3 1 0
6 5 0

output:

190

result:

ok single line: '190'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3764kb

input:

10 14 51
6 5 0
8 10 0
9 8 0
3 10 0
6 4 0
3 4 0
4 10 0
8 3 0
9 8 0
1 2 0
7 9 0
5 4 0
3 6 0
2 7 0

output:

-1

result:

ok single line: '-1'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3724kb

input:

10 14 55
5 5 82801
3 4 748185
6 10 98839
3 8 797926
5 3 57690
9 7 37956
4 6 926122
10 2 958237
8 1 40578
9 2 62884
2 8 145245
8 5 426166
1 9 880408
7 2 162816

output:

926145

result:

ok single line: '926145'

Test #4:

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

input:

9 15 97
1 1 990149
6 4 393083
4 7 171280
6 7 635660
8 6 123113
1 2 384925
6 7 507533
8 6 416969
3 4 975110
2 5 575466
2 4 72458
7 9 923003
5 3 590414
4 8 733761
7 5 440313

output:

923052

result:

ok single line: '923052'

Test #5:

score: 5
Accepted
time: 0ms
memory: 4060kb

input:

10 14 54
9 2 881274
7 8 356423
3 10 853386
2 10 677512
4 9 834731
8 6 91987
9 4 907844
1 5 652146
2 1 60718
6 5 555396
3 7 531810
6 6 401437
5 3 593446
6 4 295196

output:

853416

result:

ok single line: '853416'

Test #6:

score: 5
Accepted
time: 0ms
memory: 12160kb

input:

9266 19317 1
2000 3207 0
8069 4574 0
4857 8821 0
909 2661 0
7210 4774 0
826 7545 0
4283 4611 0
1229 8673 0
6341 9026 0
802 1762 0
300 473 0
4052 3766 0
7111 5319 0
1990 6824 0
852 475 0
6355 2588 0
5422 3626 0
4821 8355 0
4834 3221 0
4271 2262 0
7394 355 0
2847 6719 0
9089 2365 0
5663 422 0
1473 164...

output:

2594

result:

ok single line: '2594'

Test #7:

score: 5
Accepted
time: 5ms
memory: 12364kb

input:

9867 19871 1
9288 6774 0
541 9347 0
6950 4826 0
6587 180 0
7573 2835 0
3347 5023 0
9466 2489 0
6733 4683 0
6602 3743 0
4904 5408 0
5450 8761 0
3978 757 0
1145 693 0
1468 5549 0
9020 5597 0
4440 2108 0
7673 8305 0
9334 1140 0
3547 8505 0
8427 6898 0
9442 8015 0
9340 8140 0
1554 3692 0
9050 9376 0
781...

output:

2877

result:

ok single line: '2877'

Test #8:

score: 5
Accepted
time: 5ms
memory: 12000kb

input:

9342 19240 1
249 8909 363065
7613 6678 408923
6498 4312 540704
8171 6096 761352
6802 1281 739632
2957 2957 120021
3220 8158 562021
2148 7482 723634
1758 5739 525798
4926 1915 619426
6351 8751 712231
2663 856 188902
2198 3030 289802
9100 3893 970430
4207 6036 61420
47 824 62081
8715 8435 132002
1783 ...

output:

1001128

result:

ok single line: '1001128'

Test #9:

score: 5
Accepted
time: 5ms
memory: 12108kb

input:

9513 18340 1
4654 8721 10267
515 6153 327507
8226 4028 335114
4721 4217 756930
5060 1050 858391
5698 7278 571067
1986 6553 42520
6238 7193 190453
3114 1405 877455
9508 8508 279405
5233 6525 871266
7195 7195 71784
6229 3086 801474
115 9026 131532
5871 1341 826938
2327 2637 975366
4580 2807 303507
696...

output:

999770

result:

ok single line: '999770'

Test #10:

score: 5
Accepted
time: 5ms
memory: 12232kb

input:

9572 18518 1
4142 7857 878799
5686 677 765800
4940 3448 573893
1991 8493 302843
1793 2837 528763
3828 3770 888931
7475 2040 31638
4722 7971 126370
2030 1064 104636
9154 145 678140
3680 5416 196350
7231 7591 381499
7372 5404 953492
1366 4379 181509
7630 7911 480363
4289 9121 899481
1593 1325 336779
8...

output:

1000022

result:

ok single line: '1000022'

Test #11:

score: 5
Accepted
time: 34ms
memory: 12532kb

input:

9640 18640 55
1955 5950 0
3202 7642 0
9543 8057 0
2009 904 0
3859 9114 0
6215 4770 0
901 9112 0
40 8654 0
3708 4823 0
4710 1206 0
2682 7482 0
7252 1525 0
5742 2055 0
6433 1846 0
4655 7575 0
1869 3137 0
981 3256 0
6787 8775 0
9457 1928 0
6474 5027 0
1360 571 0
7907 2457 0
5727 880 0
3259 3716 0
8725 ...

output:

3025

result:

ok single line: '3025'

Test #12:

score: 5
Accepted
time: 55ms
memory: 12504kb

input:

9755 19120 88
4148 2875 0
5217 8212 0
2881 6290 0
8403 7450 0
6922 3068 0
1467 8661 0
8142 4011 0
2356 2117 0
1159 8427 0
6059 2953 0
4504 5230 0
1703 4652 0
7681 2262 0
4733 5664 0
3598 8005 0
388 388 0
9408 3377 0
5046 7386 0
2869 3002 0
8532 6788 0
6290 1193 0
4644 8820 0
3881 9139 0
3869 8824 0
...

output:

2992

result:

ok single line: '2992'

Test #13:

score: 5
Accepted
time: 57ms
memory: 12412kb

input:

9840 18511 80
8357 7609 0
2141 6907 0
6725 6524 0
2513 4614 0
4090 1499 0
5135 9333 0
774 1936 0
578 578 0
8208 4206 0
3331 1916 0
5851 2702 0
2848 4654 0
6111 5807 0
163 9509 0
4682 9576 0
7242 612 0
2395 8303 0
7920 8018 0
7942 2593 0
8913 6226 0
8671 3339 0
6888 8133 0
5391 881 0
6802 3427 0
6244...

output:

3360

result:

ok single line: '3360'

Test #14:

score: 5
Accepted
time: 45ms
memory: 12464kb

input:

9504 18794 51
899 900 637797
5745 5751 70221
2068 2076 270062
343 344 142285
4313 4314 91858
2183 2184 69574
5732 5734 991959
1879 1886 382888
6423 6424 57934
4691 4692 886459
1374 1375 802248
6748 6749 473133
6505 6506 799627
8447 8448 157324
1661 1662 72178
4100 4110 233663
6621 6622 411454
4098 4...

output:

974202

result:

ok single line: '974202'

Test #15:

score: 5
Accepted
time: 67ms
memory: 12852kb

input:

9821 18934 78
746 747 944389
5436 5437 947846
667 675 550292
4773 4779 96464
600 601 66269
8006 8010 470573
9713 9720 708785
2879 2885 227304
5562 5563 217676
840 841 188647
3502 3509 281168
3232 3234 105962
6779 6780 701790
8318 8327 12272
6431 6439 552094
5467 5468 838401
251 254 88679
3486 3496 2...

output:

977418

result:

ok single line: '977418'

Test #16:

score: 5
Accepted
time: 73ms
memory: 12372kb

input:

9693 19498 97
500 8929 466939
4695 350 665912
2712 9144 132548
5668 7376 817512
2406 3652 786389
5057 5831 706611
692 2140 98634
3534 7603 10675
6251 5172 38255
8065 6935 238603
7948 92 550809
4899 6376 590515
6963 7095 182197
2775 4360 89655
4029 1959 380597
7563 7265 701907
5957 2574 728146
7210 8...

output:

999585

result:

ok single line: '999585'

Test #17:

score: 5
Accepted
time: 56ms
memory: 12480kb

input:

9646 18363 83
435 121 888409
1613 6126 682103
6754 1494 826961
2568 7398 272799
961 2869 658914
9276 7979 771435
949 6590 853475
9198 181 445785
5848 4847 393874
6724 1611 746891
7801 287 339837
400 2493 533151
9400 8136 465405
6802 464 450995
1806 4308 910622
2541 141 550812
3363 6559 675984
8991 8...

output:

1001478

result:

ok single line: '1001478'

Test #18:

score: 5
Accepted
time: 57ms
memory: 12324kb

input:

9313 18764 75
9266 2428 96888
1703 1499 51313
8426 9041 675850
7608 3527 752630
3283 466 412454
2093 5586 82055
3713 8741 632957
2580 8365 489655
2415 83 810805
6581 1608 304463
5207 1053 578271
5788 3384 195722
1592 927 182777
1648 1844 419354
46 7764 624893
4184 7389 264998
7131 3424 698477
3440 4...

output:

999375

result:

ok single line: '999375'

Test #19:

score: 5
Accepted
time: 52ms
memory: 12404kb

input:

9708 18428 71
7276 2226 213027
3520 1734 914615
7363 7837 753125
6798 5303 688090
9369 2710 315744
203 8935 324640
7938 9099 342555
3149 4617 886453
6430 8948 268190
8092 4771 633297
4645 5213 945040
4352 4352 517062
8746 6419 124499
2970 1884 555057
3858 4767 105670
7890 1267 477651
6086 6877 86834...

output:

1000177

result:

ok single line: '1000177'

Test #20:

score: 5
Accepted
time: 47ms
memory: 12220kb

input:

9490 19373 68
2413 8708 526411
9155 6622 92153
1990 2864 804840
6073 2924 595953
5487 8201 618375
4342 8047 42740
8420 3186 221604
6191 2577 555739
4022 4792 765954
8929 3200 403240
5390 7213 547290
2346 6643 425759
6069 3059 263528
3957 6471 785024
7409 4747 419974
6662 5627 327971
3941 4828 17760
...

output:

1000416

result:

ok single line: '1000416'