Submission #1231786

#TimeUsernameProblemLanguageResultExecution timeMemory
1231786kl0989eRail (IOI14_rail)C++20
30 / 100
206 ms15992 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int, int> #define pl pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define fi first #define se second #define pb push_back #define all(x) (x).begin(),(x).end() /*void findLocation(int n, int f, int loc[], int tpe[]) { loc[0]=f; tpe[0]=1; vi dst(n,0); int mn=1; for (int i=1; i<n; i++) { dst[i]=getDistance(0,i); if (dst[i]<dst[mn]) { mn=i; } } loc[mn]=f+dst[mn]; tpe[mn]=2; for (int i=1; i<n; i++) { if (i==mn) { continue; } if (getDistance(mn,i)<dst[i]) { loc[i]=f+2*dst[mn]-dst[i]; tpe[i]=1; } else { loc[i]=f+dst[i]; tpe[i]=2; } } }*/ map<pi,int> mem; int get(int i, int j) { if (mem.count({i,j})) { return mem[{i,j}]; } if (mem.count({j,i})) { return mem[{j,i}]; } return mem[{i,j}]=getDistance(i,j); } void find(int k, int side, vi inds, int loc[], int tpe[]) { if (inds.size()==0) { return; } int mn=inds[0]; for (auto i:inds) { if (get(k,i)<get(k,mn)) { mn=i; } } loc[mn]=loc[k]+side*get(k,mn); tpe[mn]=(side==1?2:1); vi indsl,indsr; for (auto i:inds) { if (i==mn) { continue; } if (get(mn,i)<get(k,i)) { if (get(mn,i)<get(k,mn)) { loc[i]=loc[k]+side*2*get(k,mn)-side*get(k,i); tpe[i]=(side==1?1:2); } else { indsl.pb(i); } } else { indsr.pb(i); } } find(k,side,indsr,loc,tpe); find(mn,-side,indsl,loc,tpe); } void findLocation(int n, int f, int loc[], int tpe[]) {// sub 3 for (int i=0; i<n; i++) { mem[{i,i}]=0; } loc[0]=f; tpe[0]=1; vi inds(n-1); iota(all(inds),1); find(0,1,inds,loc,tpe); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...