Submission #607637

#TimeUsernameProblemLanguageResultExecution timeMemory
607637MohamedFaresNebiliRail (IOI14_rail)C++14
100 / 100
122 ms102524 KiB
#include <bits/stdc++.h>
#include "rail.h"
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
 
            using namespace std;
 
            using ll = long long;
            using ld = long double;
 
            #define ff first
            #define ss second
            #define pb push_back
            #define all(x) (x).begin(), (x).end()
            #define lb lower_bound
 
            const int MOD = 998244353;
 
            int DP[5005][5005], K[1000001];
            int query(int i, int j) {
                if(i == j) return 0;
                if(DP[i][j] != -1)
                    return DP[i][j];
                return DP[i][j] = DP[j][i] = getDistance(i, j);
            }
 
            void findLocation(int n, int first, int location[], int stype[]) {
              	memset(DP, -1, sizeof DP);
              	memset(K, -1, sizeof K);
                array<int, 2> A[n]; A[0] = {0, 0};
                location[0] = first, stype[0] = 1;
                for(int l = 1; l < n; l++)
                    A[l] = {query(0, l), l};
                sort(A, A + n);
                int L = 0, R = A[1][1];
                stype[R] = 2; location[R] = first + A[1][0];
                K[location[R]] = 1;
 
                for(int l = 2; l < n; l++) {
                    int i = A[l][1];
                    int D = location[R] - query(R, i);
                    int C = location[L] + query(L, i);
                    int md = (C + D) / 2;
                    if(K[md] == -1) {
                        if(md >= location[0]) K[md] = 0;
                        else K[md] = 1;
                    }
                    if(K[md]) {
                        location[i] = D;
                        K[D] = 0; stype[i] = 1;
                        if(D < location[L]) L = i;
                    }
                    else  {
                        location[i] = C;
                        K[C] = 1; stype[i] = 2;
                        if(C > location[R]) R = i;
                    }
                }
            }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...