제출 #1020503

#제출 시각아이디문제언어결과실행 시간메모리
1020503vjudge1Roller Coaster Railroad (IOI16_railroad)C++17
34 / 100
49 ms10036 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int inf = 1e9 + 100; const ll INF = 1e18 + 100; int n; ll dp[1<<16][16]; int a[200100]; int b[200100]; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t){ n = s.size(); for(int i = 0; i < n; i++){ a[i] = s[i]; b[i] = t[i]; } if(n <= 16){ for(int x = 0; x < (1<<n); x++){ fill(dp[x], dp[x] + n, INF); if(!x) continue; if(__builtin_popcount(x) == 1){ for(int i = 0; i < n; i++){ if(x & (1<<i)) dp[x][i] = 0; } } else{ for(int i = 0; i < n; i++){ if(x & (1<<i)){ int y = x ^ (1<<i); for(int j = 0; j < n; j++){ if(y & (1<<j)){ dp[x][i] = min(dp[x][i], dp[y][j] + max(0, t[j] - s[i])); } } } } } } return *min_element(dp[(1<<n)-1], dp[(1<<n)-1] + n); } else{ vector<int> ord; for(int i = 0; i < n; i++){ ord.push_back(i); } sort(ord.begin(), ord.end(), [](int i, int j){ return a[i] < a[j]; }); for(int i = 1; i < n; i++){ if(a[ord[i]] < b[ord[i-1]]) return 1; } 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...