# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
575343 |
2022-06-10T08:42:25 Z |
Theo830 |
Rail (IOI14_rail) |
C++17 |
|
66 ms |
724 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "rail.h"
void findLocation(int n, int first, int location[], int stype[]){
location[0] = first;
stype[0] = 1;
if(n == 1){
return;
}
ll dist[n] = {0};
ll dist2[n] = {0};
vector<ii>arr;
f(i,1,n){
dist[i] = getDistance(0,i);
arr.pb(ii(dist[i],i));
}
sort(all(arr));
ll D = arr[0].S;
location[D] = first + arr[0].F;
stype[D] = 2;
f(i,0,n){
if(i != D){
dist2[i] = getDistance(D,i);
}
}
vector<ii>left,right;
f(i,1,n){
if(i != D){
if(dist[i] < dist2[i]){
right.pb(ii(dist[i],i));
}
else{
left.pb(ii(dist2[i],i));
}
}
}
sort(all(left));
sort(all(right));
ll last = D;
for(auto x:right){
ll A = x.F - dist[last];
ll posa = getDistance(last,x.S);
assert(posa >= A);
if(posa == A){
location[x.S] = location[last] - A;
stype[x.S] = 1;
}
else{
location[x.S] = location[last] + A;
stype[x.S] = 2;
last = x.S;
}
}
last = 0;
for(auto x:left){
ll A = x.F - dist2[last];
ll posa = getDistance(last,x.S);
assert(posa >= A);
if(posa == A){
location[x.S] = location[last] + A;
stype[x.S] = 2;
}
else{
location[x.S] = location[last] - A;
stype[x.S] = 1;
last = x.S;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |