이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e18;
const int i_inf = 1e9;
const ll mod = 1e9+7;
mt19937 _rand(time(NULL));
const int mxn = 5005;
#include "rail.h"
int d0[mxn];
int dp[mxn];
/*
int getDistance(int i, int j){
cout<<"? "<<i<<' '<<j<<endl;
int ret;
cin >> ret;
return ret;
}
*/
vector<int> L;
vector<int> R;
void findLocation(int N, int first, int location[], int stype[]){
location[0] = first;
stype[0] = 1;
if(N == 1) return;
fr(i, 1, N){
d0[i] = getDistance(0, i);
}
int p = 1;
fr(i, 1, N) if(d0[i] < d0[p]) p = i;
location[p] = location[0] + d0[p];
stype[p] = 2;
if(N == 2) return;
dp[0] = d0[p];
fr(i, 1, N){
if(i == p) continue;
dp[i] = getDistance(p, i);
}
fr(i, 1, N){
if(i == p) continue;
if(d0[i] == d0[p] + dp[i]){
L.pb(i);
}
else{
R.pb(i);
}
}
sort(all(R), [](const int &i, const int &j){
return d0[i] < d0[j];
});
vector<int> pivots;
pivots.pb(p);
for(auto u : R){
bool ok = false;
int piv = pivots.back();
int w = getDistance(piv, u);
int candpos = location[piv] - w;
if(candpos > location[0]){
for(auto pi : pivots){
if(location[pi] > candpos){
if(getDistance(pi, u) == location[pi] - candpos){
ok = true;
}
break;
}
}
if(ok){
stype[u] = 1;
location[u] = candpos;
continue;
}
}
stype[u] = 2;
location[u] = location[0] + d0[u];
pivots.pb(u);
}
pivots.clear();
for(auto u : L){
bool ok = false;
if(!pivots.empty()){
int piv = pivots.back();
int w = getDistance(piv, u);
int candpos = location[piv] + w;
if(candpos < location[p]){
for(auto pi : pivots){
if(location[pi] < candpos){
if(getDistance(pi, u) == candpos - location[pi]){
ok = true;
}
break;
}
}
if(ok){
stype[u] = 2;
location[u] = candpos;
}
}
}
stype[u] = 1;
location[u] = location[p] - dp[u];
pivots.pb(u);
}
/*
if(N == 1){
return;
}
fr(i, 1, N){
d0[i] = getDistance(0, i);
}
int minD = 1e9;
int p = 0;
fr(i, 1, N){
if(d0[i] < minD){
minD = d0[i];
p = i;
}
}
d1[0] = d0[p];
fr(i, 1, N){
if(i == p) continue;
d1[i] = getDistance(p, i);
}
fr(i, 0, N){
if(i == p || i == 0) continue;
if(d0[i] == d1[i] + d0[p]){
L.pb(i);
}
else{
R.pb(i);
}
}
sort(all(R), [](const int &i, const int &j){
return d0[i] < d0[j];
});
location[p] = location[0] + d0[p];
stype[p] = 2;
if(N == 2){
return;
}
queue<int> P;
P.push(p);
for(auto u : R){
while(!P.empty()){
int piv = P.front();
int w = getDistance(piv, u);
if(d0[u] == d0[piv] + w){
location[u] = location[piv] - w;
stype[u] = 1;
break;
}
else{
P.pop();
}
}
if(P.empty()){
P.push(u);
location[u] = location[0] + d0[u];
stype[u] = 2;
}
}
int p2;
minD = 1e9;
fr(i, 0, N){
if(i == p) continue;
if(d1[i] < minD){
minD = d1[i];
p2 = i;
}
}
L.pb(0);
sort(all(L), [](const int &i, const int &j){
return d1[i] < d1[j];
});
location[p2] = location[p] - d1[p2];
stype[p2] = 1;
queue<int> P2;
P2.push(p2);
for(auto u : L){
if(u == p2) continue;
while(!P2.empty()){
int piv = P2.front();
int w = getDistance(piv, u);
if(d1[u] == d1[piv] + w){
location[u] = location[piv] + w;
stype[u] = 2;
break;
}
else{
P2.pop();
}
}
if(P2.empty()){
location[u] = location[p] - d1[u];
stype[u] = 1;
P2.push(u);
}
}
*/
}
/*
int main(){
int loc[mxn];
int sty[mxn];
findLocation(4, 3, loc, sty);
fr(i, 0, 5){
cout<<loc[i]<<' ';
}
cout<<endl;
fr(i, 0, 5){
cout<<sty[i]<<' ';
}
cout<<endl;
}
*/
/*
0 1 2 3 4 5 6 7
( ) ( )
3 0 1 2
*/
/*3
5
8
9
2
5
6
5
8
1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |