# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
601550 |
2022-07-22T07:49:26 Z |
Mamedov |
Rail (IOI14_rail) |
C++17 |
|
86 ms |
588 KB |
#pragma GCC optimize ("O3")
#include "rail.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define piii pair<pii, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define f first
#define s second
#define oo 1000000001
#define eb emplace_back
#define pb push_back
#define mpr make_pair
#define size(v) (int)v.size()
#define ln '\n'
#define ull unsigned long long
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void findLocation(int N, int first, int location[], int stype[]) {
vector<pii>d0(N);
d0[0] = mpr(0, 0);
for (int i = 1; i < N; ++i) {
d0[i].f = getDistance(0, i);
d0[i].s = i;
}
location[0] = first;
stype[0] = 1;
sort(all(d0));
if (N > 1) {
int L = 0, R = d0[1].s;
stype[R] = 2;
location[R] = location[0] + d0[1].f;
vector<pii>C, D;
C.eb(mpr(-location[L], L));
D.eb(mpr(location[R], R));
for (int itr = 2; itr < N; ++itr) {
int i = d0[itr].s;
int dLi = getDistance(L, i);
int dRi = getDistance(R, i);
/// L i R stype[i] = 1
auto p = upper_bound(all(D), mpr(location[R] - dRi, i));
if (location[R] - dRi > location[L] && p != D.end() && 2 * location[p->s] - dLi - location[L] == location[R] - dRi) {
stype[i] = 1;
location[i] = location[R] - dRi;
continue;
}
/// L i R stype[i] = 2
p = upper_bound(all(C), mpr(-(location[L] + dLi), i));
if (location[L] + dLi < location[R] && p != C.end() && dRi - location[R] + 2 * location[p->s] == location[L] + dLi) {
stype[i] = 2;
location[i] = location[L] + dLi;
continue;
}
/// i L R
if (d0[itr].f == d0[1].f + dRi - (location[R] - location[d0[1].s])) {
stype[i] = 1;
location[i] = location[R] - dRi;
C.eb(mpr(-location[i], i));
L = i;
} else {
/// L R i
stype[i] = 2;
location[i] = location[L] + dLi;
D.eb(mpr(location[i], i));
R = i;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
388 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
388 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
392 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
512 KB |
Output is correct |
2 |
Correct |
86 ms |
516 KB |
Output is correct |
3 |
Correct |
75 ms |
520 KB |
Output is correct |
4 |
Correct |
75 ms |
520 KB |
Output is correct |
5 |
Correct |
73 ms |
504 KB |
Output is correct |
6 |
Correct |
69 ms |
588 KB |
Output is correct |
7 |
Correct |
67 ms |
504 KB |
Output is correct |
8 |
Correct |
74 ms |
504 KB |
Output is correct |
9 |
Correct |
66 ms |
512 KB |
Output is correct |
10 |
Correct |
67 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
504 KB |
Output is correct |
2 |
Correct |
71 ms |
512 KB |
Output is correct |
3 |
Correct |
65 ms |
520 KB |
Output is correct |
4 |
Correct |
80 ms |
504 KB |
Output is correct |
5 |
Correct |
67 ms |
508 KB |
Output is correct |
6 |
Correct |
66 ms |
512 KB |
Output is correct |
7 |
Correct |
66 ms |
588 KB |
Output is correct |
8 |
Correct |
66 ms |
504 KB |
Output is correct |
9 |
Correct |
70 ms |
588 KB |
Output is correct |
10 |
Correct |
72 ms |
512 KB |
Output is correct |
11 |
Correct |
68 ms |
504 KB |
Output is correct |
12 |
Correct |
65 ms |
520 KB |
Output is correct |
13 |
Correct |
68 ms |
588 KB |
Output is correct |
14 |
Correct |
68 ms |
588 KB |
Output is correct |
15 |
Correct |
77 ms |
508 KB |
Output is correct |
16 |
Correct |
74 ms |
516 KB |
Output is correct |
17 |
Correct |
68 ms |
512 KB |
Output is correct |
18 |
Correct |
70 ms |
516 KB |
Output is correct |
19 |
Correct |
66 ms |
504 KB |
Output is correct |
20 |
Correct |
72 ms |
512 KB |
Output is correct |