Submission #1116688

#TimeUsernameProblemLanguageResultExecution timeMemory
1116688NotLinuxRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
129 ms14356 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; const long long inf = 1e18 + 7; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int) s.size(); if(n <= 16){ long long dp[n][1 << n]; for(int i = 0;i<n;i++)for(int j = 0;j<(1<<n);j++)dp[i][j] = inf; dp[0][0] = 0; long long ans = inf; for(int j = 0;j<(1<<n);j++){ for(int i = 0;i<n;i++){ if(j == ((1<<n)-1)){ ans = min(ans , dp[i][j]); } for(int k = 0;k<n;k++){ if((j & (1 << k)) == 0){ int cost = max(0 , t[i] - s[k]); if(j == 0)cost = 0; dp[k][j | (1 << k)] = min(dp[k][j | (1 << k)] , dp[i][j] + 1ll * cost); } } } } return ans; } pair < int , int > arr[n]; for(int i = 0;i<n;i++)arr[i] = {t[i] , s[i]}; sort(arr , arr + n); multiset < pair < int , int > > ste; for(int i = 0;i<n;i++)ste.insert({s[i] , t[i]}); int sayac = 0; for(int i = n-1;i>=0;i--){ auto it = ste.lower_bound({arr[i].first , 0}); if(it == ste.end()){ // cout << "failed " << arr[i].second << " " << arr[i].first << endl; sayac++; } else{ if(*it == make_pair(arr[i].second , arr[i].first)){ // cout << "failed " << arr[i].second << " " << arr[i].first << endl; ++it; } if(it == ste.end())sayac++; else { // cout << arr[i].second << " " << arr[i].first << " -> " << (*it).first << " " << (*it).second << endl; ste.erase(it); } } } return sayac <= 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...