#include "rail.h"
#include <bits/stdc++.h>
using namespace std ;
#define ii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<ii>
int from0[5010] , from1[5010] ;
vii le , ri , D , C ;
bool cmp(ii a, ii b){
return a.se < b.se ;
}
void findLocation(int n, int zr , int loc[], int tp[]){
int mn = 1e9 , opt = -1 ;
for(int i=1;i<n;i++) {
from0[i] = getDistance(0, i) ;
if(from0[i] < mn){
mn = from0[i] ;
opt = i ;
}
}
from1[0] = from0[opt] ;
loc[0] = zr ; tp[0] = 1 ;
loc[opt] = zr + from0[opt] ; tp[opt] = 2 ;
for(int i=1 ; i<n ;i++){
if(i == opt) continue ;
from1[i] = getDistance( opt , i ) ;
if(from1[i] + from0[opt] == from0[i]){
if(from1[i] > from0[opt]) le.push_back({i , from1[i]}) ;
else loc[i] = loc[opt] - from1[i] , tp[i] = 1 ;
}
else{
ri.push_back({i , from0[i]}) ;
}
}
sort(le.begin() , le.end() , cmp ) ;
sort(ri.begin() , ri.end() , cmp ) ;
for(ii v : ri){
if(D.empty()) {
D.push_back(v) ;
loc[v.fi] = loc[0] + v.se ;
tp[v.fi] = 2 ;
}
else{
ii cur = D.back() ;
int dst = getDistance(cur.fi , v.fi) ;
bool chk = 0 ;
for(ii nd : D){
if(nd.se + dst - cur.se + nd.se == v.se){
tp[v.fi] = 1 ;
loc[v.fi] = loc[nd.fi] - (dst - cur.se + nd.se) ;
chk = 1 ;
break ;
}
}
if(!chk) {
D.push_back(v) ;
loc[v.fi] = loc[0] + v.se ;
tp[v.fi] = 2 ;
}
}
}
D.clear() ;
for(ii v : le){
if(D.empty()) {
D.push_back(v) ;
loc[v.fi] = loc[opt] - v.se ;
tp[v.fi] = 1 ;
}
else{
ii cur = D.back() ;
int dst = getDistance(cur.fi , v.fi) ;
bool chk = 0 ;
for(ii nd : D){
if(nd.se + dst - cur.se + nd.se == v.se){
tp[v.fi] = 2 ;
loc[v.fi] = loc[nd.fi] + (dst - cur.se + nd.se) ;
chk = 1 ;
break ;
}
}
if(!chk) {
D.push_back(v) ;
loc[v.fi] = loc[opt] - v.se ;
tp[v.fi] = 1 ;
}
}
}
// for(int i=0;i<n;i++) printf("%d %d\n" , loc[i] , tp[i]) ;
return ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Correct |
3 ms |
516 KB |
Output is correct |
7 |
Correct |
2 ms |
516 KB |
Output is correct |
8 |
Correct |
2 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
3 |
Correct |
2 ms |
636 KB |
Output is correct |
4 |
Correct |
4 ms |
636 KB |
Output is correct |
5 |
Correct |
2 ms |
636 KB |
Output is correct |
6 |
Correct |
3 ms |
640 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
892 KB |
Output is correct |
2 |
Correct |
94 ms |
892 KB |
Output is correct |
3 |
Correct |
95 ms |
892 KB |
Output is correct |
4 |
Correct |
91 ms |
892 KB |
Output is correct |
5 |
Correct |
94 ms |
892 KB |
Output is correct |
6 |
Correct |
96 ms |
892 KB |
Output is correct |
7 |
Correct |
98 ms |
892 KB |
Output is correct |
8 |
Correct |
127 ms |
892 KB |
Output is correct |
9 |
Correct |
93 ms |
892 KB |
Output is correct |
10 |
Correct |
98 ms |
892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
892 KB |
Output is correct |
2 |
Correct |
103 ms |
892 KB |
Output is correct |
3 |
Correct |
93 ms |
892 KB |
Output is correct |
4 |
Correct |
96 ms |
892 KB |
Output is correct |
5 |
Correct |
96 ms |
892 KB |
Output is correct |
6 |
Correct |
105 ms |
892 KB |
Output is correct |
7 |
Correct |
104 ms |
896 KB |
Output is correct |
8 |
Correct |
137 ms |
896 KB |
Output is correct |
9 |
Correct |
105 ms |
896 KB |
Output is correct |
10 |
Correct |
106 ms |
896 KB |
Output is correct |
11 |
Correct |
95 ms |
896 KB |
Output is correct |
12 |
Correct |
96 ms |
896 KB |
Output is correct |
13 |
Correct |
93 ms |
896 KB |
Output is correct |
14 |
Correct |
95 ms |
896 KB |
Output is correct |
15 |
Correct |
94 ms |
896 KB |
Output is correct |
16 |
Correct |
97 ms |
896 KB |
Output is correct |
17 |
Correct |
95 ms |
896 KB |
Output is correct |
18 |
Correct |
99 ms |
896 KB |
Output is correct |
19 |
Correct |
94 ms |
896 KB |
Output is correct |
20 |
Correct |
97 ms |
896 KB |
Output is correct |