제출 #617555

#제출 시각아이디문제언어결과실행 시간메모리
617555Dremix10Roller Coaster Railroad (IOI16_railroad)C++17
34 / 100
224 ms524288 KiB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#ifdef dremix
    #define p(x) cerr<<#x<<" = "<<x<<endl;
    #define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
    #define pp(x) cerr<<#x<<" = ("<<x.F<<" - "<<x.S<<")"<<endl;
    #define pv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u<<", ";cerr<<"}"<<endl;
    #define ppv(x) cerr<<#x<<" = {";for(auto u : x)cerr<<u.F<<"-"<<u.S<<", ";cerr<<"}"<<endl;
#else
    #define p(x) {}
    #define p2(x,y) {}
    #define pp(x) {}
    #define pv(x) {}
    #define ppv(x) {}
#endif
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const int N = 3e5+5;
const int MOD = 1e9+7;
const ll INF = 1e18+5;


long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
    int n = (int) s.size();
    int m = (1<<n);
    ll dp[m][n];

    int i,j;

    for(i=0;i<m;i++)
        for(j=0;j<n;j++)
            dp[i][j] = INF;

    for(j=0;j<n;j++)
        dp[(1<<j)][j] = 0;

    int k;
    for(i=1;i<m;i++){
        for(j=0;j<n;j++){
            if(dp[i][j] == INF)continue;
            for(k=0;k<n;k++){
                if(i&(1<<k))continue;
                dp[i+(1<<k)][k] = min(dp[i+(1<<k)][k],dp[i][j] + max(0,t[j] - s[k]));   
            }
        }
    }

    ll ans = INF;
    for(i=0;i<n;i++)
        ans = min(ans,dp[m-1][i]);
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...