Submission #99973

#TimeUsernameProblemLanguageResultExecution timeMemory
99973dwscRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
166 ms16128 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; long long memo[20][100000]; int n; int arr1[20],arr2[20]; long long dp(int prev,int bm){ if (bm == (1<<n)-1) return 0; if (memo[prev][bm] != -1) return memo[prev][bm]; memo[prev][bm] = 1e18; for (int i = 0; i < n; i++){ if (bm & (1<<i)) continue; int cost = max(0,arr2[prev]-arr1[i]); memo[prev][bm] = min(memo[prev][bm],dp(i,bm+(1<<i))+cost); } return memo[prev][bm]; } long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { n = (int) s.size(); if (n > 20) return 0; for (int i = 0; i < n; i++){ arr1[i] = s[i]; arr2[i] = t[i]; } for (int i = 0; i < 20; i++)for (int j = 0; j < 100000; j++) memo[i][j] = -1; long long ans = 1e18; for (int i = 0; i < n; i++) ans = min(ans,dp(i,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...