Submission #1034929

#TimeUsernameProblemLanguageResultExecution timeMemory
1034929aymanrsRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
82 ms8632 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 = s.size(); if(n<=16){ long long dp[1<<n][n]; for(int i = 0;i < n;i++) dp[(1<<n)-1][i] = 0; for(int b = (1<<n)-2;b;b--){ for(int j = 0;j < n;j++){ if(!((b>>j)&1)) continue; dp[b][j] = LONG_LONG_MAX; for(int k = 0;k < n;k++){ if((b>>k)&1) continue; dp[b][j] = min(dp[b][j], dp[b|(1<<k)][k]+max(0, t[j]-s[k])); } } } long long ans = LONG_LONG_MAX; for(int i = 0;i < n;i++) ans = min(ans, dp[1<<i][i]); return ans; } int os[n], ot[n];for(int i = 0;i < n;i++){os[i]=s[i];ot[i]=i;}; sort(os, os+n); sort(ot, ot+n, [&t,&s](int a, int b){ if(t[a]!=t[b]) return t[a]<t[b]; return s[a]>s[b]; }); int mi = INT_MAX; bool joker = false; for(int _ = n-1, d=1; _ >= 0;_--,d++){ int i = ot[_]; if(!joker) mi = min(int(lower_bound(os, os+n, s[i])-os), mi); int l = lower_bound(os, os+n, t[i])-os; if(joker && l <= mi) l++; l = n-l; if(l<d){ if(joker) return 1; d--; joker = true; } } 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...