이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e9;
const int MX = 5000 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
#ifndef LOCAL
#include "rail.h"
#endif
#ifdef LOCAL
int getDistance(int u, int v){
return 0;
}
#endif
struct st{
int idx,x;
};
int N,d[MX][MX];
st L,R;
V<st>tyC,tyD;
void get(int i, int j){
d[i][j]=d[j][i]=getDistance(i,j);
}
void findLocation(int N, int first, int X[], int ty[]){
::N=N;
if(N==1){
X[0]=first;
ty[0]=1;
return;
}
d[0][0]=0;
vpi vec;
FOR(i,1,N){
get(0,i);
vec.eb(d[0][i],i);
}
sort(all(vec));
tyC.pb({0,first});
L=tyC[0];
X[0]=L.x;
ty[0]=1;
tyD.pb({vec[0].se,first+vec[0].fi});
R=tyD[0];
X[R.idx]=R.x;
ty[R.idx]=2;
int fir=1;
for(auto it: vec){
if(fir){
fir=0;
continue;
}
st k; k.idx=it.se;
get(k.idx,L.idx);
get(k.idx,R.idx);
//Case 1
k.x=L.x+d[k.idx][L.idx];
int f=0;
for(st p: tyC){
if(p.x<k.x){
f|=(k.x-p.x+R.x-p.x==d[k.idx][R.idx]);
}
}
if(f){
X[k.idx]=k.x;
ty[k.idx]=2;
tyD.pb(k);
if(k.x>R.idx) R=k;
continue;
}
//Case 2
k.x=R.x-d[k.idx][R.idx];
for(st p: tyD){
if(p.x>k.x){
f|=(p.x-k.x+p.x-L.x==d[k.idx][L.idx]);
}
}
//assert(f);
X[k.idx]=k.x;
ty[k.idx]=1;
tyC.pb(k);
if(k.x<L.idx) L=k;
}
}
#ifdef LOCAL
int main(){
IO();
}
#endif
//Change your approach
# | 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... |