# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
225837 |
2020-04-21T19:56:42 Z |
DS007 |
Dreaming (IOI13_dreaming) |
C++14 |
|
169 ms |
27768 KB |
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
const int MN = 1e5 + 5;
vector<pair<int, int>> adj[MN];
bool explored[MN];
vector<int> dia, dist;
multimap<int, int> m[MN];
int dp[MN];
int dfs(int v, int p = -1, int last = 0) {
int val = max(last, dp[v]);
for (auto i : adj[v]) {
if (i.first == p)
continue;
auto itr = m[v].rbegin();
if (itr->second == i.first && m[v].size() == 1)
val = min(val, dfs(i.first, v, last + i.second));
else if (itr->second == i.first)
val = min(val, dfs(i.first, v, max(last, (++itr)->first) + i.second));
else
val = min(val, dfs(i.first, v, max(last, itr->first) + i.second));
}
dp[v] = max(dp[v], last);
return val;
}
void pre(int v) {
explored[v] = true;
for (auto i : adj[v]) {
if (!explored[i.first])
pre(i.first), m[v].insert({dp[i.first] + i.second, i.first});
}
dp[v] = m[v].empty() ? 0 : m[v].rbegin()->first;
}
pair<int, int> longest(int v, int p = -1) {
pair<int, int> ans = {0, v};
for (auto i : adj[v]) {
if (i.first == p)
continue;
auto temp = longest(i.first, v);
ans = max(ans, {temp.first + i.second, temp.second});
}
return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for (int i = 0; i < M; i++) {
adj[A[i]].emplace_back(B[i], T[i]);
adj[B[i]].emplace_back(A[i], T[i]);
}
for (int i = 0; i < N; i++) {
if (!explored[i]) {
pre(i), dist.push_back(dfs(i));
auto temp = longest(i);
dia.push_back(longest(temp.second).first);
}
}
sort(dist.begin(), dist.end());
pair<int, int> pen[dist.size()];
int lp = 0, rp = dist.size() - 1;
bool check = true;
for (int i = 0; i < dist.size(); i++) {
if (check)
pen[i] = {lp++, dist[i]};
else
pen[i] = {rp--, dist[i]};
check = !check;
}
sort(pen, pen + dist.size());
int ans = *max_element(dia.begin(), dia.end()), temp = 0;
for (int i = 0; i < dist.size(); i++) {
ans = max(ans, temp + pen[i].second);
temp = max(temp, pen[i].second) + L;
}
return ans;
}
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:72:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < dist.size(); i++) {
~~^~~~~~~~~~~~~
dreaming.cpp:83:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < dist.size(); i++) {
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
23032 KB |
Output is correct |
2 |
Correct |
84 ms |
22904 KB |
Output is correct |
3 |
Correct |
56 ms |
18808 KB |
Output is correct |
4 |
Correct |
17 ms |
9728 KB |
Output is correct |
5 |
Correct |
16 ms |
8832 KB |
Output is correct |
6 |
Correct |
27 ms |
10872 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
43 ms |
13580 KB |
Output is correct |
9 |
Correct |
57 ms |
16504 KB |
Output is correct |
10 |
Correct |
10 ms |
7552 KB |
Output is correct |
11 |
Correct |
107 ms |
18312 KB |
Output is correct |
12 |
Correct |
149 ms |
20472 KB |
Output is correct |
13 |
Correct |
10 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
23032 KB |
Output is correct |
2 |
Correct |
84 ms |
22904 KB |
Output is correct |
3 |
Correct |
56 ms |
18808 KB |
Output is correct |
4 |
Correct |
17 ms |
9728 KB |
Output is correct |
5 |
Correct |
16 ms |
8832 KB |
Output is correct |
6 |
Correct |
27 ms |
10872 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
43 ms |
13580 KB |
Output is correct |
9 |
Correct |
57 ms |
16504 KB |
Output is correct |
10 |
Correct |
10 ms |
7552 KB |
Output is correct |
11 |
Correct |
107 ms |
18312 KB |
Output is correct |
12 |
Correct |
149 ms |
20472 KB |
Output is correct |
13 |
Correct |
10 ms |
7552 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
8 ms |
7424 KB |
Output is correct |
16 |
Correct |
8 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
8 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7424 KB |
Output is correct |
23 |
Correct |
8 ms |
7424 KB |
Output is correct |
24 |
Correct |
9 ms |
7424 KB |
Output is correct |
25 |
Correct |
8 ms |
7424 KB |
Output is correct |
26 |
Correct |
8 ms |
7424 KB |
Output is correct |
27 |
Correct |
8 ms |
7424 KB |
Output is correct |
28 |
Correct |
8 ms |
7424 KB |
Output is correct |
29 |
Correct |
8 ms |
7424 KB |
Output is correct |
30 |
Correct |
8 ms |
7424 KB |
Output is correct |
31 |
Correct |
8 ms |
7424 KB |
Output is correct |
32 |
Correct |
9 ms |
7424 KB |
Output is correct |
33 |
Correct |
9 ms |
7424 KB |
Output is correct |
34 |
Correct |
9 ms |
7424 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
38 |
Correct |
8 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
23032 KB |
Output is correct |
2 |
Correct |
84 ms |
22904 KB |
Output is correct |
3 |
Correct |
56 ms |
18808 KB |
Output is correct |
4 |
Correct |
17 ms |
9728 KB |
Output is correct |
5 |
Correct |
16 ms |
8832 KB |
Output is correct |
6 |
Correct |
27 ms |
10872 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
43 ms |
13580 KB |
Output is correct |
9 |
Correct |
57 ms |
16504 KB |
Output is correct |
10 |
Correct |
10 ms |
7552 KB |
Output is correct |
11 |
Correct |
107 ms |
18312 KB |
Output is correct |
12 |
Correct |
149 ms |
20472 KB |
Output is correct |
13 |
Correct |
10 ms |
7552 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
8 ms |
7424 KB |
Output is correct |
16 |
Correct |
8 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
8 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7424 KB |
Output is correct |
23 |
Correct |
8 ms |
7424 KB |
Output is correct |
24 |
Correct |
9 ms |
7424 KB |
Output is correct |
25 |
Correct |
8 ms |
7424 KB |
Output is correct |
26 |
Correct |
8 ms |
7424 KB |
Output is correct |
27 |
Correct |
8 ms |
7424 KB |
Output is correct |
28 |
Correct |
8 ms |
7424 KB |
Output is correct |
29 |
Correct |
8 ms |
7424 KB |
Output is correct |
30 |
Correct |
8 ms |
7424 KB |
Output is correct |
31 |
Correct |
8 ms |
7424 KB |
Output is correct |
32 |
Correct |
9 ms |
7424 KB |
Output is correct |
33 |
Correct |
9 ms |
7424 KB |
Output is correct |
34 |
Correct |
9 ms |
7424 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
38 |
Correct |
8 ms |
7424 KB |
Output is correct |
39 |
Correct |
90 ms |
23032 KB |
Output is correct |
40 |
Correct |
107 ms |
23032 KB |
Output is correct |
41 |
Correct |
57 ms |
18808 KB |
Output is correct |
42 |
Correct |
17 ms |
9728 KB |
Output is correct |
43 |
Correct |
8 ms |
7424 KB |
Output is correct |
44 |
Correct |
8 ms |
7424 KB |
Output is correct |
45 |
Correct |
9 ms |
7424 KB |
Output is correct |
46 |
Correct |
8 ms |
7424 KB |
Output is correct |
47 |
Correct |
8 ms |
7424 KB |
Output is correct |
48 |
Correct |
9 ms |
7424 KB |
Output is correct |
49 |
Correct |
8 ms |
7552 KB |
Output is correct |
50 |
Correct |
9 ms |
7424 KB |
Output is correct |
51 |
Correct |
9 ms |
7424 KB |
Output is correct |
52 |
Correct |
8 ms |
7424 KB |
Output is correct |
53 |
Correct |
8 ms |
7424 KB |
Output is correct |
54 |
Correct |
9 ms |
7424 KB |
Output is correct |
55 |
Correct |
8 ms |
7424 KB |
Output is correct |
56 |
Correct |
8 ms |
7424 KB |
Output is correct |
57 |
Correct |
120 ms |
19064 KB |
Output is correct |
58 |
Correct |
117 ms |
19064 KB |
Output is correct |
59 |
Correct |
116 ms |
19064 KB |
Output is correct |
60 |
Correct |
120 ms |
18940 KB |
Output is correct |
61 |
Correct |
108 ms |
19064 KB |
Output is correct |
62 |
Correct |
127 ms |
19072 KB |
Output is correct |
63 |
Correct |
102 ms |
18820 KB |
Output is correct |
64 |
Correct |
112 ms |
18808 KB |
Output is correct |
65 |
Correct |
117 ms |
19068 KB |
Output is correct |
66 |
Correct |
148 ms |
19064 KB |
Output is correct |
67 |
Correct |
109 ms |
19064 KB |
Output is correct |
68 |
Correct |
116 ms |
19064 KB |
Output is correct |
69 |
Correct |
119 ms |
19320 KB |
Output is correct |
70 |
Correct |
124 ms |
19320 KB |
Output is correct |
71 |
Correct |
8 ms |
7424 KB |
Output is correct |
72 |
Correct |
10 ms |
7680 KB |
Output is correct |
73 |
Correct |
10 ms |
7808 KB |
Output is correct |
74 |
Correct |
10 ms |
7808 KB |
Output is correct |
75 |
Correct |
10 ms |
7808 KB |
Output is correct |
76 |
Correct |
10 ms |
7808 KB |
Output is correct |
77 |
Correct |
10 ms |
7680 KB |
Output is correct |
78 |
Correct |
10 ms |
7808 KB |
Output is correct |
79 |
Correct |
10 ms |
7680 KB |
Output is correct |
80 |
Correct |
169 ms |
19092 KB |
Output is correct |
81 |
Correct |
119 ms |
18936 KB |
Output is correct |
82 |
Correct |
111 ms |
19064 KB |
Output is correct |
83 |
Correct |
118 ms |
19064 KB |
Output is correct |
84 |
Correct |
10 ms |
7808 KB |
Output is correct |
85 |
Correct |
9 ms |
7680 KB |
Output is correct |
86 |
Correct |
9 ms |
7680 KB |
Output is correct |
87 |
Correct |
10 ms |
7680 KB |
Output is correct |
88 |
Correct |
10 ms |
7680 KB |
Output is correct |
89 |
Correct |
9 ms |
7680 KB |
Output is correct |
90 |
Correct |
10 ms |
7680 KB |
Output is correct |
91 |
Correct |
10 ms |
7808 KB |
Output is correct |
92 |
Correct |
10 ms |
7680 KB |
Output is correct |
93 |
Correct |
10 ms |
7680 KB |
Output is correct |
94 |
Correct |
8 ms |
7424 KB |
Output is correct |
95 |
Correct |
9 ms |
7424 KB |
Output is correct |
96 |
Correct |
8 ms |
7424 KB |
Output is correct |
97 |
Correct |
8 ms |
7424 KB |
Output is correct |
98 |
Correct |
9 ms |
7424 KB |
Output is correct |
99 |
Correct |
8 ms |
7424 KB |
Output is correct |
100 |
Correct |
8 ms |
7424 KB |
Output is correct |
101 |
Correct |
8 ms |
7424 KB |
Output is correct |
102 |
Correct |
8 ms |
7424 KB |
Output is correct |
103 |
Correct |
8 ms |
7424 KB |
Output is correct |
104 |
Correct |
15 ms |
8704 KB |
Output is correct |
105 |
Correct |
25 ms |
10880 KB |
Output is correct |
106 |
Correct |
8 ms |
7424 KB |
Output is correct |
107 |
Correct |
42 ms |
13596 KB |
Output is correct |
108 |
Correct |
57 ms |
16508 KB |
Output is correct |
109 |
Correct |
8 ms |
7552 KB |
Output is correct |
110 |
Correct |
84 ms |
18296 KB |
Output is correct |
111 |
Correct |
99 ms |
20344 KB |
Output is correct |
112 |
Correct |
9 ms |
7552 KB |
Output is correct |
113 |
Correct |
134 ms |
27768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
13040 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
23032 KB |
Output is correct |
2 |
Correct |
84 ms |
22904 KB |
Output is correct |
3 |
Correct |
56 ms |
18808 KB |
Output is correct |
4 |
Correct |
17 ms |
9728 KB |
Output is correct |
5 |
Correct |
16 ms |
8832 KB |
Output is correct |
6 |
Correct |
27 ms |
10872 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
43 ms |
13580 KB |
Output is correct |
9 |
Correct |
57 ms |
16504 KB |
Output is correct |
10 |
Correct |
10 ms |
7552 KB |
Output is correct |
11 |
Correct |
107 ms |
18312 KB |
Output is correct |
12 |
Correct |
149 ms |
20472 KB |
Output is correct |
13 |
Correct |
10 ms |
7552 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Incorrect |
9 ms |
7552 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
23032 KB |
Output is correct |
2 |
Correct |
84 ms |
22904 KB |
Output is correct |
3 |
Correct |
56 ms |
18808 KB |
Output is correct |
4 |
Correct |
17 ms |
9728 KB |
Output is correct |
5 |
Correct |
16 ms |
8832 KB |
Output is correct |
6 |
Correct |
27 ms |
10872 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
43 ms |
13580 KB |
Output is correct |
9 |
Correct |
57 ms |
16504 KB |
Output is correct |
10 |
Correct |
10 ms |
7552 KB |
Output is correct |
11 |
Correct |
107 ms |
18312 KB |
Output is correct |
12 |
Correct |
149 ms |
20472 KB |
Output is correct |
13 |
Correct |
10 ms |
7552 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
8 ms |
7424 KB |
Output is correct |
16 |
Correct |
8 ms |
7424 KB |
Output is correct |
17 |
Correct |
8 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
9 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
8 ms |
7424 KB |
Output is correct |
22 |
Correct |
10 ms |
7424 KB |
Output is correct |
23 |
Correct |
8 ms |
7424 KB |
Output is correct |
24 |
Correct |
9 ms |
7424 KB |
Output is correct |
25 |
Correct |
8 ms |
7424 KB |
Output is correct |
26 |
Correct |
8 ms |
7424 KB |
Output is correct |
27 |
Correct |
8 ms |
7424 KB |
Output is correct |
28 |
Correct |
8 ms |
7424 KB |
Output is correct |
29 |
Correct |
8 ms |
7424 KB |
Output is correct |
30 |
Correct |
8 ms |
7424 KB |
Output is correct |
31 |
Correct |
8 ms |
7424 KB |
Output is correct |
32 |
Correct |
9 ms |
7424 KB |
Output is correct |
33 |
Correct |
9 ms |
7424 KB |
Output is correct |
34 |
Correct |
9 ms |
7424 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
38 |
Correct |
8 ms |
7424 KB |
Output is correct |
39 |
Correct |
90 ms |
23032 KB |
Output is correct |
40 |
Correct |
107 ms |
23032 KB |
Output is correct |
41 |
Correct |
57 ms |
18808 KB |
Output is correct |
42 |
Correct |
17 ms |
9728 KB |
Output is correct |
43 |
Correct |
8 ms |
7424 KB |
Output is correct |
44 |
Correct |
8 ms |
7424 KB |
Output is correct |
45 |
Correct |
9 ms |
7424 KB |
Output is correct |
46 |
Correct |
8 ms |
7424 KB |
Output is correct |
47 |
Correct |
8 ms |
7424 KB |
Output is correct |
48 |
Correct |
9 ms |
7424 KB |
Output is correct |
49 |
Correct |
8 ms |
7552 KB |
Output is correct |
50 |
Correct |
9 ms |
7424 KB |
Output is correct |
51 |
Correct |
9 ms |
7424 KB |
Output is correct |
52 |
Correct |
8 ms |
7424 KB |
Output is correct |
53 |
Correct |
8 ms |
7424 KB |
Output is correct |
54 |
Correct |
9 ms |
7424 KB |
Output is correct |
55 |
Correct |
8 ms |
7424 KB |
Output is correct |
56 |
Correct |
8 ms |
7424 KB |
Output is correct |
57 |
Correct |
120 ms |
19064 KB |
Output is correct |
58 |
Correct |
117 ms |
19064 KB |
Output is correct |
59 |
Correct |
116 ms |
19064 KB |
Output is correct |
60 |
Correct |
120 ms |
18940 KB |
Output is correct |
61 |
Correct |
108 ms |
19064 KB |
Output is correct |
62 |
Correct |
127 ms |
19072 KB |
Output is correct |
63 |
Correct |
102 ms |
18820 KB |
Output is correct |
64 |
Correct |
112 ms |
18808 KB |
Output is correct |
65 |
Correct |
117 ms |
19068 KB |
Output is correct |
66 |
Correct |
148 ms |
19064 KB |
Output is correct |
67 |
Correct |
109 ms |
19064 KB |
Output is correct |
68 |
Correct |
116 ms |
19064 KB |
Output is correct |
69 |
Correct |
119 ms |
19320 KB |
Output is correct |
70 |
Correct |
124 ms |
19320 KB |
Output is correct |
71 |
Correct |
8 ms |
7424 KB |
Output is correct |
72 |
Correct |
10 ms |
7680 KB |
Output is correct |
73 |
Correct |
10 ms |
7808 KB |
Output is correct |
74 |
Correct |
10 ms |
7808 KB |
Output is correct |
75 |
Correct |
10 ms |
7808 KB |
Output is correct |
76 |
Correct |
10 ms |
7808 KB |
Output is correct |
77 |
Correct |
10 ms |
7680 KB |
Output is correct |
78 |
Correct |
10 ms |
7808 KB |
Output is correct |
79 |
Correct |
10 ms |
7680 KB |
Output is correct |
80 |
Correct |
169 ms |
19092 KB |
Output is correct |
81 |
Correct |
119 ms |
18936 KB |
Output is correct |
82 |
Correct |
111 ms |
19064 KB |
Output is correct |
83 |
Correct |
118 ms |
19064 KB |
Output is correct |
84 |
Correct |
10 ms |
7808 KB |
Output is correct |
85 |
Correct |
9 ms |
7680 KB |
Output is correct |
86 |
Correct |
9 ms |
7680 KB |
Output is correct |
87 |
Correct |
10 ms |
7680 KB |
Output is correct |
88 |
Correct |
10 ms |
7680 KB |
Output is correct |
89 |
Correct |
9 ms |
7680 KB |
Output is correct |
90 |
Correct |
10 ms |
7680 KB |
Output is correct |
91 |
Correct |
10 ms |
7808 KB |
Output is correct |
92 |
Correct |
10 ms |
7680 KB |
Output is correct |
93 |
Correct |
10 ms |
7680 KB |
Output is correct |
94 |
Correct |
8 ms |
7424 KB |
Output is correct |
95 |
Correct |
9 ms |
7424 KB |
Output is correct |
96 |
Correct |
8 ms |
7424 KB |
Output is correct |
97 |
Correct |
8 ms |
7424 KB |
Output is correct |
98 |
Correct |
9 ms |
7424 KB |
Output is correct |
99 |
Correct |
8 ms |
7424 KB |
Output is correct |
100 |
Correct |
8 ms |
7424 KB |
Output is correct |
101 |
Correct |
8 ms |
7424 KB |
Output is correct |
102 |
Correct |
8 ms |
7424 KB |
Output is correct |
103 |
Correct |
8 ms |
7424 KB |
Output is correct |
104 |
Correct |
15 ms |
8704 KB |
Output is correct |
105 |
Correct |
25 ms |
10880 KB |
Output is correct |
106 |
Correct |
8 ms |
7424 KB |
Output is correct |
107 |
Correct |
42 ms |
13596 KB |
Output is correct |
108 |
Correct |
57 ms |
16508 KB |
Output is correct |
109 |
Correct |
8 ms |
7552 KB |
Output is correct |
110 |
Correct |
84 ms |
18296 KB |
Output is correct |
111 |
Correct |
99 ms |
20344 KB |
Output is correct |
112 |
Correct |
9 ms |
7552 KB |
Output is correct |
113 |
Correct |
134 ms |
27768 KB |
Output is correct |
114 |
Incorrect |
39 ms |
13040 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |