#include "rail.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int get(int x,int y) {
if (x == y)
return 0;
return getDistance(x,y);
}
void findLocation(int N, int first, int location[], int stype[]) {
int n = N;
vi d0(n),d1(n);
for (int i = 0;i < n;++i)
stype[i] = -1;
for (int i = 0;i < n;++i)
d0[i] = get(0,i);
const int a = 0;
const int b = min_element(d0.begin() + 1,d0.end()) - d0.begin();
location[a] = first;
stype[a] = 1;
location[b] = first + d0[b];
stype[b] = 2;
for (int i = 0;i < n;++i)
d1[i] = get(b,i);
vi lf,rg;
for (int i = 0;i < n;++i)
if (i != a && i != b) {
if (d0[i] == d0[b] + d1[i]) {
if (d1[i] < d0[b]) {
location[i] = location[b] - d1[i];
stype[i] = 1;
} else {
lf.pb(i);
}
} else {
rg.pb(i);
}
}
sort(all(lf),[&](int x,int y) {
return d1[x] < d1[y];
});
sort(all(rg),[&](int x,int y) {
return d0[x] < d0[y];
});
int lst = a;
map < int , int > was;
for (int i = 0;i < n;++i)
if (stype[i] > 0)
was[location[i]] = stype[i];
for (auto it : lf) {
const int ds = get(lst,it);
int ps = location[lst] + (location[b] - location[lst] + ds - d1[it]) / 2;
if (was.count(ps) && was[ps] == 1) {
location[it] = location[lst] + ds;
stype[it] = 2;
was[location[it]] = 2;
} else {
location[it] = location[b] - d1[it];
stype[it] = 1;
lst = it;
was[location[it]] = 1;
}
}
lst = b;
for (auto it : rg) {
const int ds = get(lst,it);
int ps = location[lst] - (location[lst] - location[a] + ds - d0[it]) / 2;
if (was.count(ps) && was[ps] == 2) {
location[it] = location[lst] - ds;
stype[it] = 1;
was[location[it]] = 1;
} else {
location[it] = location[a] + d0[it];
stype[it] = 2;
lst = it;
was[location[it]] = 2;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Correct |
3 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
644 KB |
Output is correct |
8 |
Correct |
3 ms |
644 KB |
Output is correct |
9 |
Correct |
3 ms |
688 KB |
Output is correct |
10 |
Correct |
2 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
700 KB |
Output is correct |
2 |
Correct |
2 ms |
700 KB |
Output is correct |
3 |
Correct |
2 ms |
700 KB |
Output is correct |
4 |
Correct |
3 ms |
700 KB |
Output is correct |
5 |
Correct |
4 ms |
700 KB |
Output is correct |
6 |
Correct |
4 ms |
704 KB |
Output is correct |
7 |
Correct |
3 ms |
708 KB |
Output is correct |
8 |
Correct |
3 ms |
712 KB |
Output is correct |
9 |
Correct |
4 ms |
716 KB |
Output is correct |
10 |
Correct |
3 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
1100 KB |
Output is correct |
2 |
Correct |
94 ms |
1132 KB |
Output is correct |
3 |
Correct |
91 ms |
1176 KB |
Output is correct |
4 |
Correct |
95 ms |
1272 KB |
Output is correct |
5 |
Correct |
99 ms |
1316 KB |
Output is correct |
6 |
Correct |
89 ms |
1356 KB |
Output is correct |
7 |
Correct |
129 ms |
1452 KB |
Output is correct |
8 |
Correct |
95 ms |
1496 KB |
Output is correct |
9 |
Correct |
91 ms |
1664 KB |
Output is correct |
10 |
Correct |
95 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
1664 KB |
Output is correct |
2 |
Correct |
98 ms |
1664 KB |
Output is correct |
3 |
Correct |
86 ms |
1668 KB |
Output is correct |
4 |
Correct |
91 ms |
1740 KB |
Output is correct |
5 |
Correct |
96 ms |
1756 KB |
Output is correct |
6 |
Correct |
89 ms |
1800 KB |
Output is correct |
7 |
Correct |
95 ms |
1972 KB |
Output is correct |
8 |
Correct |
131 ms |
1972 KB |
Output is correct |
9 |
Correct |
107 ms |
1972 KB |
Output is correct |
10 |
Correct |
100 ms |
2108 KB |
Output is correct |
11 |
Correct |
87 ms |
2108 KB |
Output is correct |
12 |
Correct |
94 ms |
2108 KB |
Output is correct |
13 |
Correct |
92 ms |
2124 KB |
Output is correct |
14 |
Correct |
92 ms |
2168 KB |
Output is correct |
15 |
Correct |
92 ms |
2200 KB |
Output is correct |
16 |
Correct |
92 ms |
2268 KB |
Output is correct |
17 |
Correct |
92 ms |
2416 KB |
Output is correct |
18 |
Correct |
94 ms |
2416 KB |
Output is correct |
19 |
Correct |
97 ms |
2504 KB |
Output is correct |
20 |
Correct |
106 ms |
2584 KB |
Output is correct |