Submission #982450

#TimeUsernameProblemLanguageResultExecution timeMemory
982450MarwenElarbiRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
273 ms524288 KiB
#include<bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #define fi first #define se second #define ll long long #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int)s.size(); long long dp[(1<<n)][n]; for (int i = 0; i < (1<<n); ++i) { for (int j = 0; j < n; ++j) { dp[i][j]=1e18; } } for (int i = 0; i < n; ++i) { dp[(1<<i)][i]=0; } for (int mask = 1; mask < (1<<n); ++mask) { for (int i = 0; i < n; ++i) { if((1<<i)&mask){ int submask=mask-(1<<i); for (int j = 0; j < n; ++j) { if((1<<j)&submask){ dp[mask][i]=min(dp[mask][i],dp[submask][j]+max(0,t[j]-s[i])); } } } } } long long ans=1e18; for (int i = 0; i < n; ++i) { ans=min(ans,dp[(1<<n)-1][i]); } return ans; } /*int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; assert(1 == scanf("%d", &n)); std::vector<int> s(n), t(n); for (int i = 0; i < n; ++i) assert(2 == scanf("%d%d", &s[i], &t[i])); long long ans = plan_roller_coaster(s, t); printf("%lld\n", ans); 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...