QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138423#4363. Branch AssignmentPetroTarnavskyi#WA 226ms204288kbC++171.6kb2023-08-11 18:15:102023-08-11 18:15:12

Judging History

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

  • [2023-08-11 18:15:12]
  • 评测
  • 测评结果:WA
  • 用时:226ms
  • 内存:204288kb
  • [2023-08-11 18:15:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 5000 + 47;
vector<PII> g[2][N];
int d[2][N];

LL dp[N][N];


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, b, groups, m;
	cin >> n >> b >> groups >> m;
	
	
	FOR(i, 0, m){
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		g[0][u].PB(MP(v, w));
		g[1][v].PB(MP(u, w));
	}
	FOR(t, 0, 2){
		FOR(i, 0, n)
			d[t][i] = 1e9;	
		d[t][b] = 0;
		
		set<PII> q;
		q.insert(MP(0, b));
		while(SZ(q)){
			int v = q.begin()->S;
			q.erase(q.begin());
			for(auto [to, w] : g[t][v]){
				if(d[t][to] <= d[t][v] + w)
					continue;
				q.erase(MP(d[t][to], to));
				d[t][to] = d[t][v] + w;
				q.insert(MP(d[t][to], to));
			}
		}
	}
	FOR(i, 0, n)
		d[0][i] += d[1][i];
	sort(d[0], d[0] + b);
	n = b;
	
	FOR(i, 0, N)
	FOR(j, 0, N)
		dp[i][j] = 1e18;
	
	
	dp[0][0] = 0;
	vector<LL> pref(n + 1, 0);
	FOR(i, 0, n)
		pref[i + 1] = pref[i] + d[0][i];
	
	FOR(k, 0, groups){
		int opt = 0;
		FOR(i, 1, n + 1){
			while(opt + 1 <= i && (pref[i] - pref[opt]) * (i - opt - 1) + dp[opt][k] > (pref[i] - pref[opt + 1]) * (i - opt - 2) + dp[opt + 1][k])
				opt++;
			dp[i][k + 1] = (pref[i] - pref[opt]) * (i - opt - 1) + dp[opt][k];
		}
	}
	cout << dp[n][groups] << endl;

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 15ms
memory: 202708kb

input:

5 4 2 10
5 2 1
2 5 1
3 5 5
4 5 0
1 5 1
2 3 1
3 2 5
2 4 5
2 1 1
3 4 2

output:

13

result:

ok single line: '13'

Test #2:

score: 0
Accepted
time: 16ms
memory: 202744kb

input:

5 4 2 10
5 2 1
2 5 1
3 5 5
4 5 10
1 5 1
2 3 1
3 2 5
2 4 5
2 1 1
3 4 2

output:

24

result:

ok single line: '24'

Test #3:

score: 0
Accepted
time: 11ms
memory: 202772kb

input:

5 4 3 8
1 5 15
5 1 15
2 5 2
5 2 3
3 5 1
5 3 1
4 5 2
5 4 0

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 12ms
memory: 202768kb

input:

2 1 1 2
1 2 5
2 1 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 4ms
memory: 202712kb

input:

9 4 2 11
1 2 1
2 3 2
3 4 3
4 6 4
6 8 5
8 9 6
9 7 7
7 5 8
5 8 8
7 6 9
6 1 10

output:

304

result:

ok single line: '304'

Test #6:

score: 0
Accepted
time: 4ms
memory: 203088kb

input:

5000 4999 2 9998
1 2 10000
2 1 10000
2 3 10000
3 2 10000
3 4 10000
4 3 10000
4 5 10000
5 4 10000
5 6 10000
6 5 10000
6 7 10000
7 6 10000
7 8 10000
8 7 10000
8 9 10000
9 8 10000
9 10 10000
10 9 10000
10 11 10000
11 10 10000
11 12 10000
12 11 10000
12 13 10000
13 12 10000
13 14 10000
14 13 10000
14 15...

output:

589335814500000

result:

ok single line: '589335814500000'

Test #7:

score: 0
Accepted
time: 4ms
memory: 203260kb

input:

5000 4999 100 9998
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
10 11 1
11 12 1
12 13 1
13 14 1
14 15 1
15 16 1
16 17 1
17 18 1
18 19 1
19 20 1
20 21 1
21 22 1
22 23 1
23 24 1
24 25 1
25 26 1
26 27 1
27 28 1
28 29 1
29 30 1
30 31 1
31 32 1
32 33 1
33 34 1
34 35 1
35 36 1
36 37 1
37 38 1
38...

output:

1224510000

result:

ok single line: '1224510000'

Test #8:

score: 0
Accepted
time: 103ms
memory: 204228kb

input:

5000 4900 2000 50000
3116 1995 5417
1801 380 719
4749 13 4103
1175 493 659
596 3035 2098
628 2199 2816
711 3295 5220
4888 4316 153
1007 2136 1990
1365 1579 8062
4076 1263 7023
3114 3756 2785
3695 3175 3364
2302 3474 5739
3062 3705 9620
3815 1026 7712
3991 3582 3049
3245 2397 5834
18 1456 1619
2186 4...

output:

166040058

result:

ok single line: '166040058'

Test #9:

score: 0
Accepted
time: 22ms
memory: 204228kb

input:

5000 4950 2 50000
3669 4840 0
614 3306 0
290 1311 0
2359 2891 0
3497 3550 0
3428 2623 0
1940 3386 0
3650 1263 0
2260 4950 0
1588 3186 0
4498 1773 0
4295 296 0
2956 1009 0
176 3322 0
4509 2130 0
894 4934 0
281 1204 0
1731 14 0
2405 1590 0
1315 635 0
1469 195 0
3651 647 0
82 4604 0
1171 195 0
4275 401...

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 226ms
memory: 204204kb

input:

5000 4900 4850 50000
2664 4071 4296
612 1817 6511
2292 3113 8392
961 4255 1637
4959 1976 2034
1664 4624 1380
912 3972 8714
1207 2958 2443
3503 729 2610
4920 3996 8547
63 1698 7911
948 4574 1568
1045 4886 5174
3103 4846 1519
875 3369 6492
632 2688 563
1632 3563 588
3929 1553 6982
4707 1623 1425
2762 ...

output:

1182041

result:

ok single line: '1182041'

Test #11:

score: 0
Accepted
time: 20ms
memory: 204204kb

input:

5000 4950 2 50000
1218 2222 2897
2887 2737 8305
229 2321 4170
4168 3818 9202
1790 221 4606
2545 1061 7338
1169 592 2259
4092 4087 2360
3322 1047 6485
2970 328 6695
494 4516 2381
3342 4606 4670
3612 3942 9868
834 1386 6434
1142 1782 9753
1709 1989 9597
1149 20 7387
4936 4604 4163
3505 1877 594
4564 2...

output:

254153797367

result:

ok single line: '254153797367'

Test #12:

score: 0
Accepted
time: 23ms
memory: 204188kb

input:

5000 4999 70 50000
1060 1927 0
305 2800 4
2718 2374 9
3134 2200 2
962 1174 7
3953 4904 10
534 4874 10
812 4718 10
4015 728 0
1142 1263 2
864 4957 2
2368 2520 0
814 843 0
1628 3903 8
2067 1860 6
3054 449 6
1611 993 1
4114 4522 3
4264 1745 2
2946 3536 6
901 1625 3
1861 3452 10
1953 179 1
1112 271 3
13...

output:

2767588

result:

ok single line: '2767588'

Test #13:

score: 0
Accepted
time: 223ms
memory: 204288kb

input:

5000 4950 4900 50000
1683 1801 0
3511 3698 0
2360 4358 0
75 2274 0
1670 2492 0
3576 4624 0
1833 34 0
3759 4205 0
2081 242 0
3120 235 0
3924 4140 0
3067 3547 0
3793 644 0
4333 1287 0
2083 4043 0
2643 3799 0
4311 4466 0
4919 1 0
1458 3787 0
1870 345 0
3481 1274 0
3095 1988 0
742 4480 0
4047 3163 0
164...

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 141ms
memory: 203216kb

input:

5000 4999 3000 9998
1 5000 1
5000 1 1
2 5000 1
5000 2 1
3 5000 1
5000 3 1
4 5000 1
5000 4 1
5 5000 1
5000 5 1
6 5000 1
5000 6 1
7 5000 1
5000 7 1
8 5000 1
5000 8 1
9 5000 1
5000 9 1
10 5000 1
5000 10 1
11 5000 1
5000 11 1
12 5000 1
5000 12 1
13 5000 1
5000 13 1
14 5000 1
5000 14 1
15 5000 1
5000 15 ...

output:

7996

result:

ok single line: '7996'

Test #15:

score: -100
Wrong Answer
time: 8ms
memory: 202724kb

input:

38 37 5 74
1 38 1
38 1 0
2 38 1
38 2 0
3 38 1
38 3 0
4 38 1
38 4 0
5 38 1
38 5 0
6 38 1
38 6 0
7 38 1
38 7 0
8 38 1
38 8 0
9 38 1
38 9 0
10 38 1
38 10 0
11 38 1
38 11 0
12 38 1
38 12 0
13 38 1
38 13 0
14 38 1
38 14 0
15 38 1
38 15 0
16 38 1
38 16 0
17 38 1
38 17 0
18 38 1
38 18 0
19 38 1
38 19 0
20 ...

output:

554

result:

wrong answer 1st lines differ - expected: '544', found: '554'