# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1053328 |
2024-08-11T10:32:03 Z |
Tob |
Sky Walking (IOI19_walk) |
C++14 |
|
4000 ms |
255572 KB |
#include <bits/stdc++.h>
#include "walk.h"
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
const int N = 1e5 + 7, C = 12e5 + 7;
const ll inf = 1e18;
int n, m, cnt;
ll g[N], h[N], dis[C];
vector <pii> ad[N], adj[C];
map <int, vector <int> > ma;
void Edge(int x, int y, int val) {
adj[x].pb({y, val});
adj[y].pb({x, val});
}
ll min_distance(vi x, vi h, vi l, vi r, vi y, int sta, int en) {
n = x.size(); m = l.size();
for (int i = 0; i < n; i++) ma[h[i]].pb(i);
for (int i = 0; i < m; i++) ma[y[i]].pb(i+n);
set <int> st;
cnt = n;
auto itt = --ma.end();
while (1) {
auto it = *itt;
vector <int> v = it.S;
for (auto xx : v) {
if (xx < n) st.insert(xx);
else {
xx -= n;
auto p = st.lower_bound(l[xx]);
int la = -1;
while (p != st.end() && *p <= r[xx]) {
ad[*p].pb({it.F, cnt});
if (la != -1) Edge(cnt-1, cnt, x[*p]-x[la]);
la = *p;
++p;
cnt++;
}
}
}
if (itt == ma.begin()) break;
--itt;
}
for (int i = 0; i < n; i++) {
reverse(all(ad[i]));
ad[i].erase(unique(all(ad[i])), ad[i].end());
if (ad[i].empty()) continue;
Edge(i, ad[i][0].S, ad[i][0].F);
for (int j = 1; j < ad[i].size(); j++) Edge(ad[i][j-1].S, ad[i][j].S, ad[i][j].F-ad[i][j-1].F);
}
set <pii> s;
s.insert({0, sta});
for (int i = 0; i < cnt; i++) dis[i] = inf;
dis[sta] = 0;
while (!s.empty()) {
auto p = s.begin();
int xx = p -> S;
s.erase(p);
for (auto y : adj[xx]) {
if (dis[xx] + y.S < dis[y.F]) {
if (dis[y.F] != inf) s.erase({dis[y.F], y.F});
dis[y.F] = dis[xx] + y.S;
s.insert({dis[y.F], y.F});
}
}
}
return (dis[en] >= inf) ? -1 : dis[en];
}
Compilation message
walk.cpp: In function 'll min_distance(vi, vi, vi, vi, vi, int, int)':
walk.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int j = 1; j < ad[i].size(); j++) Edge(ad[i][j-1].S, ad[i][j].S, ad[i][j].F-ad[i][j-1].F);
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
31320 KB |
Output is correct |
2 |
Correct |
4 ms |
31320 KB |
Output is correct |
3 |
Correct |
4 ms |
31324 KB |
Output is correct |
4 |
Correct |
4 ms |
31324 KB |
Output is correct |
5 |
Correct |
4 ms |
31320 KB |
Output is correct |
6 |
Correct |
4 ms |
31320 KB |
Output is correct |
7 |
Correct |
4 ms |
31324 KB |
Output is correct |
8 |
Correct |
5 ms |
31320 KB |
Output is correct |
9 |
Correct |
4 ms |
31324 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31324 KB |
Output is correct |
12 |
Correct |
4 ms |
31324 KB |
Output is correct |
13 |
Correct |
4 ms |
31324 KB |
Output is correct |
14 |
Correct |
4 ms |
31320 KB |
Output is correct |
15 |
Correct |
4 ms |
31324 KB |
Output is correct |
16 |
Correct |
4 ms |
31324 KB |
Output is correct |
17 |
Correct |
4 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
31324 KB |
Output is correct |
2 |
Correct |
4 ms |
31320 KB |
Output is correct |
3 |
Correct |
402 ms |
96636 KB |
Output is correct |
4 |
Execution timed out |
4067 ms |
116416 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
42836 KB |
Output is correct |
2 |
Runtime error |
237 ms |
255572 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
42836 KB |
Output is correct |
2 |
Runtime error |
237 ms |
255572 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
31320 KB |
Output is correct |
2 |
Correct |
4 ms |
31320 KB |
Output is correct |
3 |
Correct |
4 ms |
31324 KB |
Output is correct |
4 |
Correct |
4 ms |
31324 KB |
Output is correct |
5 |
Correct |
4 ms |
31320 KB |
Output is correct |
6 |
Correct |
4 ms |
31320 KB |
Output is correct |
7 |
Correct |
4 ms |
31324 KB |
Output is correct |
8 |
Correct |
5 ms |
31320 KB |
Output is correct |
9 |
Correct |
4 ms |
31324 KB |
Output is correct |
10 |
Correct |
4 ms |
31324 KB |
Output is correct |
11 |
Correct |
4 ms |
31324 KB |
Output is correct |
12 |
Correct |
4 ms |
31324 KB |
Output is correct |
13 |
Correct |
4 ms |
31324 KB |
Output is correct |
14 |
Correct |
4 ms |
31320 KB |
Output is correct |
15 |
Correct |
4 ms |
31324 KB |
Output is correct |
16 |
Correct |
4 ms |
31324 KB |
Output is correct |
17 |
Correct |
4 ms |
31324 KB |
Output is correct |
18 |
Correct |
5 ms |
31324 KB |
Output is correct |
19 |
Correct |
4 ms |
31320 KB |
Output is correct |
20 |
Correct |
402 ms |
96636 KB |
Output is correct |
21 |
Execution timed out |
4067 ms |
116416 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |