#include "rail.h"
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
void findLocation(int N, int first, int location[], int stype[])
{
int lid = 0, rid = -1;
vector<int> dist(N);
for(int i = 0; i < N; i ++){
if(i == lid)continue;
int temp = getDistance(lid, i);
dist[i] = temp;
}
vector<int> order(N);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int a, int b){return dist[a] < dist[b];});
rid = order[1];
lid = order[0];
stype[order[0]] = 1;
stype[order[1]] = 2;
location[order[0]] = first;
location[order[1]] = first + dist[rid];
map<int, int> at;
at[location[order[0]]] = order[0];
at[location[order[1]]] = order[1];
for(int i : order){
if(stype[i])continue;
int t1 = getDistance(i, lid);
int t2 = getDistance(i, rid);
int push = (location[lid] + location[rid] + t1 - t2)/2;
int last = at.find(push) == at.end() ? (push > first ? 1 : 2) : stype[at[push]];
if(last == 1){
stype[i] = 2;
location[i] = location[lid] + t1;
if(location[i] > location[rid])rid = i;
}
else{
stype[i] = 1;
location[i] = location[rid] - t2;
if(location[i] < location[lid])lid = i;
}
at[location[i]] = i;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
388 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
716 KB |
Output is correct |
2 |
Correct |
46 ms |
768 KB |
Output is correct |
3 |
Correct |
45 ms |
772 KB |
Output is correct |
4 |
Correct |
46 ms |
716 KB |
Output is correct |
5 |
Correct |
46 ms |
760 KB |
Output is correct |
6 |
Correct |
46 ms |
716 KB |
Output is correct |
7 |
Correct |
47 ms |
720 KB |
Output is correct |
8 |
Correct |
46 ms |
716 KB |
Output is correct |
9 |
Correct |
45 ms |
768 KB |
Output is correct |
10 |
Correct |
46 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
712 KB |
Output is correct |
2 |
Correct |
47 ms |
756 KB |
Output is correct |
3 |
Correct |
49 ms |
752 KB |
Output is correct |
4 |
Correct |
51 ms |
756 KB |
Output is correct |
5 |
Correct |
47 ms |
760 KB |
Output is correct |
6 |
Correct |
45 ms |
716 KB |
Output is correct |
7 |
Correct |
46 ms |
716 KB |
Output is correct |
8 |
Correct |
47 ms |
716 KB |
Output is correct |
9 |
Correct |
47 ms |
872 KB |
Output is correct |
10 |
Correct |
46 ms |
716 KB |
Output is correct |
11 |
Correct |
46 ms |
716 KB |
Output is correct |
12 |
Correct |
52 ms |
776 KB |
Output is correct |
13 |
Correct |
46 ms |
716 KB |
Output is correct |
14 |
Correct |
45 ms |
760 KB |
Output is correct |
15 |
Correct |
45 ms |
716 KB |
Output is correct |
16 |
Correct |
47 ms |
764 KB |
Output is correct |
17 |
Correct |
46 ms |
652 KB |
Output is correct |
18 |
Correct |
45 ms |
716 KB |
Output is correct |
19 |
Correct |
45 ms |
756 KB |
Output is correct |
20 |
Correct |
51 ms |
740 KB |
Output is correct |