이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |