Submission #140464

#TimeUsernameProblemLanguageResultExecution timeMemory
140464bazsi700Roller Coaster Railroad (IOI16_railroad)C++14
34 / 100
346 ms152732 KiB
#include <bits/stdc++.h> #include "railroad.h" using namespace std; #define MOD 1000000007 #define ll long long int #define vi vector<int> #define vii vector< vector<int> > #define PI 3.1415926535897932384626433832795 #define INF 9223372036854775807LL #define hashA 1257958787 #define hashB 1539500609 #define endl "\n" ll dp[17][17][66000]; ll plan_roller_coaster(vector<int> s, vector<int> t) { int n = s.size(); for(int i = 0; i < 17; i++) { for(int k = 0; k < 17; k++) { for(int j = 0; j < 66000; j++) { dp[i][k][j] = INF; } } } vector<vector<int> > masks (17,vector<int>()); for(int mask = 0; mask < (1<<n); mask++) { vector<int> setbits; for(int k = 0; k < n; k++) { if(mask&(1<<k)) { setbits.push_back(k); } } masks[setbits.size()].push_back(mask); } if(n <= 16) { for(int i = 0; i < n; i++) { dp[1][i][(1<<i)] = 0; } for(int i = 2; i <= n; i++) { for(int lst = 0; lst < n; lst++) { for(int mask : masks[i]) { if((mask&(1<<lst)) == 0) { continue; } vector<int> setbits; for(int k = 0; k < n; k++) { if(mask&(1<<k)) { setbits.push_back(k); } } int oldmask = mask^(1<<lst); for(int l : setbits) { if(l != lst) { dp[i][lst][mask] = min(dp[i][lst][mask],dp[i-1][l][oldmask]+max(0,t[l]-s[lst])); } } } } } ll ans = INF; for(int lst = 0; lst < n; lst++) { //cout << dp[n][lst][(1<<n)-1] << " "; ans = min(ans,dp[n][lst][(1<<n)-1]); } return ans; } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...