Submission #789912

#TimeUsernameProblemLanguageResultExecution timeMemory
789912ShithilaRoller Coaster Railroad (IOI16_railroad)C++14
64 / 100
66 ms11080 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int) s.size(); if(n<17) { vector<vector<long long>> dp((1<<n), vector<long long>(n,1e16)); long long kk=1; int kkpos=0; while(kkpos<n) { dp[kk][kkpos]=0; kk=kk*2; kkpos++; } for(int i=0;i<(1<<n);i++) { for(int j=0;j<n;j++) { if(((1<<j) & i)==0) { for(int k=0;k<n;k++) { if(((1<<k) & i)!=0) { long long distance=max((t[k]-s[j]),0); dp[i | (1<<j)][j]=min(dp[i | (1<<j)][j],(dp[i][k] + distance)); } } } } } long long minnimum=1e16; for(int j=0;j<n;j++) { minnimum=min(minnimum,dp[(1<<n) - 1][j]); } return minnimum; } vector<pair<int,int>> ss,tt; for(int i=0;i<n;i++) { tt.push_back({t[i], i}); ss.push_back({s[i], i}); } sort(ss.rbegin(), ss.rend()); sort(tt.rbegin(), tt.rend()); int i=0; int j=1; while(j<n) { if(ss[i].second != tt[j].second) { if(tt[j].first > ss[i].first) return 999; } else if(i != n - 1) { if(tt[j].first > ss[i + 1].first) return 999; } i++, j++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...