Submission #1116679

#TimeUsernameProblemLanguageResultExecution timeMemory
1116679NotLinuxRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
49 ms8696 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;
    }
    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...