Submission #114629

#TimeUsernameProblemLanguageResultExecution timeMemory
114629E869120Roller Coaster Railroad (IOI16_railroad)C++14
34 / 100
67 ms9848 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; long long N, A[100009], B[100009], dp[1 << 16][17]; long long plan_roller_coaster(vector<int>s, vector<int>t) { N = s.size(); for (int i = 0; i < N; i++) { A[i] = s[i]; B[i] = t[i]; } for (int i = 0; i < (1 << N); i++) { for (int j = 0; j <= N; j++) dp[i][j] = (1LL << 60); } dp[0][N] = 0; B[N] = 1; for (int i = 0; i < (1 << N); i++) { for (int j = 0; j <= N; j++) { if (dp[i][j] == (1LL << 60)) continue; for (int k = 0; k < N; k++) { if ((i & (1 << k)) != 0) continue; dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], dp[i][j] + max(0LL, B[j] - A[k])); } } } long long minx = (1LL << 60); for (int i = 0; i < N; i++) minx = min(minx, dp[(1 << N) - 1][i]); return minx; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...