#include "railroad.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <bitset>
#define pb push_back
using namespace std;
#define ll long long
vector<int>S;
vector<int>T;
vector<vector<ll>> dp((1<<17),vector<ll>(17,1e9));
ll calc_cost(int i,int j){
return max(T[i]-S[j],0);
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
S = s;T = t;
// cout << "started" << endl;
dp[1][0] = 0;
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
if((i&(1<<j)) == 0){
for(int k=0;k<n;k++){
if((i&(1<<k)) != 0){
// bitset<8> x(i);
// cout << x << " add " << j << " through k " << k << endl;
dp[i|(1<<j)][j] = min(dp[i|(1<<j)][j],dp[i][k]+calc_cost(k,j));
}
}
}
}
}
ll ans = 1e9;
for(int i=0;i<n;i++){
ans = min(ans,dp[(1<<n)-1][i]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21844 KB |
n = 2 |
2 |
Correct |
13 ms |
21864 KB |
n = 2 |
3 |
Correct |
14 ms |
21760 KB |
n = 2 |
4 |
Correct |
15 ms |
21868 KB |
n = 2 |
5 |
Correct |
14 ms |
21844 KB |
n = 2 |
6 |
Correct |
13 ms |
21860 KB |
n = 2 |
7 |
Correct |
14 ms |
21844 KB |
n = 3 |
8 |
Incorrect |
14 ms |
21764 KB |
answer is not correct: 622570517 instead of 102553483 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21844 KB |
n = 2 |
2 |
Correct |
13 ms |
21864 KB |
n = 2 |
3 |
Correct |
14 ms |
21760 KB |
n = 2 |
4 |
Correct |
15 ms |
21868 KB |
n = 2 |
5 |
Correct |
14 ms |
21844 KB |
n = 2 |
6 |
Correct |
13 ms |
21860 KB |
n = 2 |
7 |
Correct |
14 ms |
21844 KB |
n = 3 |
8 |
Incorrect |
14 ms |
21764 KB |
answer is not correct: 622570517 instead of 102553483 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
68 ms |
53836 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21844 KB |
n = 2 |
2 |
Correct |
13 ms |
21864 KB |
n = 2 |
3 |
Correct |
14 ms |
21760 KB |
n = 2 |
4 |
Correct |
15 ms |
21868 KB |
n = 2 |
5 |
Correct |
14 ms |
21844 KB |
n = 2 |
6 |
Correct |
13 ms |
21860 KB |
n = 2 |
7 |
Correct |
14 ms |
21844 KB |
n = 3 |
8 |
Incorrect |
14 ms |
21764 KB |
answer is not correct: 622570517 instead of 102553483 |
9 |
Halted |
0 ms |
0 KB |
- |