#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//never guess
//never debug without reviewing code
//never try adding ones or subtracting them
//only step by step debug when necessary
ll bit(ll x){
int k = 0;
while((1<<k)<x) k++;
return k;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = s.size();
ll dp[(int)1e5][n]; memset(dp,1,sizeof dp);
memset(dp[0],0,sizeof dp[0]);
for(int i = 1; i<(1<<n); i++){
int cnt = 0;
while((1<<cnt)<=i){
if((1<<cnt)&i){
ll mn =1e12;
for(int j = 0; j<n; j++){
mn = min(mn,dp[i-(1<<cnt)][j] + max(0,t[j]-s[cnt]));
}
dp[i][bit(i)] = min(dp[i][bit(i)],mn);
}
cnt++;
}
}
ll res = LLONG_MAX;
for(int i = 0; i<n; i++){
res = min(res,dp[(1<<n)-1][i]);
}
return res;
}
long long aplan_roller_coaster(std::vector<int> s, std::vector<int> t) {
vp32 arr;
for(int i = 0; i<s.size(); i++) arr.eb(s[i],t[i]);
sort(arr.begin(),arr.end());
ll result = 1e12;
do{
ll res = 0;
for(int i = 1; i<arr.size(); i++){
res+=max(0,arr[i-1].se-arr[i].fi);
}
result = min(result,res);
}while(next_permutation(arr.begin(),arr.end()));
return result;
}
컴파일 시 표준 에러 (stderr) 메시지
railroad.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
railroad_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |