#include "rail.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define inf 1000000000
#define MOD 1000000007
#define M 1000000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;
void findLocation(int N, int first, int location[], int stype[]) {
location[0]=first;
stype[0]=1;
vector<ii> a(N);
a[0]={0,0};
for(int i=1;i<N;i++) {
a[i]={getDistance(0,i),i};
}
sort(a.begin(),a.end());
location[a[1].nd]=first+a[1].st;
stype[a[1].nd]=2;
vector<int> rails;
rails.pb(0);
rails.pb(a[1].nd);
for(int i=2;i<N;i++) {
int dsecond=getDistance(a[1].nd,a[i].nd);
if(a[i].st==a[1].st+dsecond && location[a[1].nd]-dsecond<first) {
// on the left
int ds3=getDistance(rails[0],a[i].nd);
int uppos=location[rails[0]]+ds3;
int ne=-1;
for(int j=0;j<sz(rails);j++) {
if(location[rails[j]]<uppos && stype[rails[j]]==1) ne=rails[j];
}
if(uppos<location[0] && ~ne && dsecond==location[a[1].nd]-location[ne]+uppos-location[ne]) {
location[a[i].nd]=uppos;
stype[a[i].nd]=2;
}
else {
location[a[i].nd]=location[a[1].nd]-dsecond;
stype[a[i].nd]=1;
}
}
else {
// on the right
int ds3=getDistance(rails.back(),a[i].nd);
int dopos=location[rails.back()]-ds3;
int ne=-1;
for(int j=sz(rails)-1;j>=0;j--) {
if(location[rails[j]]>dopos && stype[rails[j]]==2) ne=rails[j];
}
if(dopos>location[0] && ~ne && a[i].st==location[ne]-dopos+location[ne]-first) {
location[a[i].nd]=dopos;
stype[a[i].nd]=1;
}
else {
location[a[i].nd]=location[0]+a[i].st;
stype[a[i].nd]=2;
}
}
if(location[a[i].nd]<location[rails[0]]) rails.insert(rails.begin(),a[i].nd);
else {
for(int j=sz(rails)-1;j>=0;j--) {
if(location[a[i].nd]>location[rails[j]]) {
rails.insert(rails.begin()+j+1,a[i].nd);
break ;
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
652 KB |
Output is correct |
2 |
Correct |
101 ms |
632 KB |
Output is correct |
3 |
Correct |
98 ms |
632 KB |
Output is correct |
4 |
Correct |
97 ms |
632 KB |
Output is correct |
5 |
Correct |
94 ms |
632 KB |
Output is correct |
6 |
Correct |
96 ms |
632 KB |
Output is correct |
7 |
Correct |
97 ms |
760 KB |
Output is correct |
8 |
Correct |
98 ms |
632 KB |
Output is correct |
9 |
Correct |
99 ms |
760 KB |
Output is correct |
10 |
Correct |
97 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
768 KB |
Output is correct |
2 |
Correct |
100 ms |
540 KB |
Output is correct |
3 |
Correct |
97 ms |
632 KB |
Output is correct |
4 |
Correct |
99 ms |
632 KB |
Output is correct |
5 |
Correct |
95 ms |
632 KB |
Output is correct |
6 |
Correct |
96 ms |
632 KB |
Output is correct |
7 |
Correct |
96 ms |
804 KB |
Output is correct |
8 |
Correct |
97 ms |
768 KB |
Output is correct |
9 |
Correct |
100 ms |
656 KB |
Output is correct |
10 |
Correct |
98 ms |
636 KB |
Output is correct |
11 |
Correct |
94 ms |
636 KB |
Output is correct |
12 |
Correct |
94 ms |
632 KB |
Output is correct |
13 |
Correct |
101 ms |
768 KB |
Output is correct |
14 |
Correct |
101 ms |
632 KB |
Output is correct |
15 |
Correct |
97 ms |
632 KB |
Output is correct |
16 |
Correct |
101 ms |
632 KB |
Output is correct |
17 |
Correct |
96 ms |
744 KB |
Output is correct |
18 |
Correct |
100 ms |
632 KB |
Output is correct |
19 |
Correct |
97 ms |
636 KB |
Output is correct |
20 |
Correct |
96 ms |
632 KB |
Output is correct |