Submission #1042743

# Submission time Handle Problem Language Result Execution time Memory
1042743 2024-08-03T10:21:33 Z aymanrs Wiring (IOI17_wiring) C++17
100 / 100
31 ms 11468 KB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;

long long min_total_length(std::vector<int> r, std::vector<int> b) {
	vector<pair<int, bool>> ev;
	for(int i : r) ev.emplace_back(i, true);
	for(int i : b) ev.emplace_back(i, false);
	sort(ev.begin(), ev.end());
	long long p[ev.size()];
	for(int i = 0;i < ev.size();i++){
		p[i] = ev[i].first;
		if(i) p[i]+=p[i-1];
	}
	long long dp[ev.size()+1], sp[ev.size()+1];
	dp[0]=0;
	fill(dp+1, dp+ev.size()+1, LONG_LONG_MAX);
	long long S = 0;
	int c[ev.size()];
	int g = 0;
	for(int i = ev.size()-1;i >= 0;){
		int j = i;
		while(j >= 0 && ev[j].second == ev[i].second) {
			j--;
		}
		long long s = 0;
		for(int k = j+1;k <= i;k++){
			c[k] = min(j >= 0 ? ev[k].first-ev[j].first : INT_MAX,
			i+1 < ev.size() ? ev[i+1].first-ev[k].first : INT_MAX);
			S += c[k];
		}
		sp[i+1]=dp[0];
		for(int k = i;k > j;k--){
			sp[k]=sp[k+1];
			s += -ev[k].first-c[k];
			if(i-k+1 <= g && dp[i-k+1] < LONG_LONG_MAX) sp[k] = min(sp[k], dp[i-k+1]+s);
		}
		g = i-j;
		dp[0] = sp[j+1];
		s = 0;
		for(int k = 1;k <= g;k++){
			s += ev[j+k].first-c[j+k];
			dp[k] = s+sp[j+k+1];
		}
		i=j;
	}
	return S+dp[0];
}

Compilation message

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0;i < ev.size();i++){
      |                ~~^~~~~~~~~~~
wiring.cpp:29:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, bool> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |    i+1 < ev.size() ? ev[i+1].first-ev[k].first : INT_MAX);
      |    ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 15 ms 8396 KB Output is correct
4 Correct 15 ms 8420 KB Output is correct
5 Correct 18 ms 8392 KB Output is correct
6 Correct 19 ms 10888 KB Output is correct
7 Correct 20 ms 10840 KB Output is correct
8 Correct 19 ms 10956 KB Output is correct
9 Correct 21 ms 10956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 424 KB Output is correct
3 Correct 30 ms 11056 KB Output is correct
4 Correct 30 ms 10648 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 29 ms 11008 KB Output is correct
19 Correct 29 ms 11024 KB Output is correct
20 Correct 31 ms 10940 KB Output is correct
21 Correct 29 ms 10896 KB Output is correct
22 Correct 30 ms 10920 KB Output is correct
23 Correct 30 ms 10948 KB Output is correct
24 Correct 31 ms 10948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 24 ms 10180 KB Output is correct
3 Correct 27 ms 10444 KB Output is correct
4 Correct 31 ms 10180 KB Output is correct
5 Correct 28 ms 10180 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 24 ms 10416 KB Output is correct
19 Correct 27 ms 10344 KB Output is correct
20 Correct 23 ms 10180 KB Output is correct
21 Correct 25 ms 10188 KB Output is correct
22 Correct 24 ms 10280 KB Output is correct
23 Correct 21 ms 10696 KB Output is correct
24 Correct 21 ms 10440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 15 ms 8396 KB Output is correct
20 Correct 15 ms 8420 KB Output is correct
21 Correct 18 ms 8392 KB Output is correct
22 Correct 19 ms 10888 KB Output is correct
23 Correct 20 ms 10840 KB Output is correct
24 Correct 19 ms 10956 KB Output is correct
25 Correct 21 ms 10956 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 424 KB Output is correct
28 Correct 30 ms 11056 KB Output is correct
29 Correct 30 ms 10648 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 29 ms 11008 KB Output is correct
44 Correct 29 ms 11024 KB Output is correct
45 Correct 31 ms 10940 KB Output is correct
46 Correct 29 ms 10896 KB Output is correct
47 Correct 30 ms 10920 KB Output is correct
48 Correct 30 ms 10948 KB Output is correct
49 Correct 31 ms 10948 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 24 ms 10180 KB Output is correct
52 Correct 27 ms 10444 KB Output is correct
53 Correct 31 ms 10180 KB Output is correct
54 Correct 28 ms 10180 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 24 ms 10416 KB Output is correct
68 Correct 27 ms 10344 KB Output is correct
69 Correct 23 ms 10180 KB Output is correct
70 Correct 25 ms 10188 KB Output is correct
71 Correct 24 ms 10280 KB Output is correct
72 Correct 21 ms 10696 KB Output is correct
73 Correct 21 ms 10440 KB Output is correct
74 Correct 23 ms 10940 KB Output is correct
75 Correct 31 ms 10528 KB Output is correct
76 Correct 27 ms 10984 KB Output is correct
77 Correct 26 ms 10416 KB Output is correct
78 Correct 25 ms 10440 KB Output is correct
79 Correct 27 ms 10436 KB Output is correct
80 Correct 22 ms 10432 KB Output is correct
81 Correct 26 ms 10540 KB Output is correct
82 Correct 21 ms 10444 KB Output is correct
83 Correct 19 ms 10696 KB Output is correct
84 Correct 20 ms 10948 KB Output is correct
85 Correct 26 ms 11468 KB Output is correct
86 Correct 24 ms 11052 KB Output is correct
87 Correct 24 ms 10956 KB Output is correct
88 Correct 23 ms 11048 KB Output is correct
89 Correct 22 ms 10948 KB Output is correct
90 Correct 29 ms 10948 KB Output is correct
91 Correct 23 ms 11020 KB Output is correct
92 Correct 26 ms 10956 KB Output is correct
93 Correct 22 ms 10956 KB Output is correct
94 Correct 25 ms 10948 KB Output is correct
95 Correct 28 ms 11084 KB Output is correct
96 Correct 22 ms 10956 KB Output is correct
97 Correct 23 ms 11024 KB Output is correct
98 Correct 23 ms 11052 KB Output is correct
99 Correct 24 ms 10956 KB Output is correct
100 Correct 27 ms 11020 KB Output is correct
101 Correct 22 ms 11096 KB Output is correct
102 Correct 28 ms 10948 KB Output is correct