| 10808 | 2024-04-15 10:30:25 | Ablablabla | Autó-tortúra | cpp17 | Time limit exceeded 0/100 | 1.601s | 40020 KiB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 7;
vector<vector<int>> tav;
vector<int> latogat;
int n, m, k, l, b;
vector<int> kut;
vector<vector<int>> dp;
int megold(int ind, int tank){
if(ind == l - 1){
if(tank < 0){
return INF;
}
return 0;
} else if(tank <= 0){
return INF;
} else if(dp[ind][tank] != -1){
return dp[ind][tank];
}
int a = megold(ind + 1, tank - tav[latogat[ind]][latogat[ind + 1]]) + tav[latogat[ind]][latogat[ind + 1]];
int mini = INF;
int minInd = 0;
for(int i = 0; i < b; i++){
if(tav[latogat[ind]][kut[i]] > tank) continue;
int akt = tav[kut[i]][latogat[ind + 1]];
if(mini > akt){
mini = akt;
minInd = kut[i];
}
}
int b = megold(ind + 1, k - mini) + tav[latogat[ind]][minInd] + tav[minInd][latogat[ind + 1]];
return dp[ind][tank] = min(a, b);
}
int main()
{
cin >> n >> m >> k;
vector<vector<int>> csucsok(n, vector<int>());
tav.assign(n, vector<int>(n, INF));
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--; b--;
csucsok[a].push_back(b);
csucsok[b].push_back(a);
tav[a][b] = 1;
tav[b][a] = 1;
}
for(int i = 0; i < n; i++){
tav[i][i] = 0;
}
for(int l = 0; l < n; l++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
tav[i][j] = min(tav[i][j], tav[i][l] + tav[l][j]);
}
}
}
cin >> l;
latogat.assign(l, 0);
for(int &x : latogat){
cin >> x;
x--;
}
cin >> b;
kut.assign(b, 0);
for(int &x : kut){
cin >> x;
x--;
}
dp.assign(l, vector<int>(k + 1, -1));
cout << megold(0, k) << "\n";
}
| Subtask | Sum | Test | Verdict | Time | Memory | ||
|---|---|---|---|---|---|---|---|
| subtask1 | 0/0 | ||||||
| 1 | Accepted | 3ms | 1812 KiB | ||||
| 2 | Time limit exceeded | 1.57s | 20936 KiB | ||||
| subtask2 | 0/12 | ||||||
| 3 | Runtime error | 3ms | 2376 KiB | ||||
| 4 | Accepted | 3ms | 2408 KiB | ||||
| 5 | Runtime error | 3ms | 2748 KiB | ||||
| 6 | Runtime error | 3ms | 3028 KiB | ||||
| 7 | Runtime error | 3ms | 2976 KiB | ||||
| 8 | Runtime error | 3ms | 3144 KiB | ||||
| 9 | Runtime error | 3ms | 3232 KiB | ||||
| 10 | Runtime error | 3ms | 3144 KiB | ||||
| subtask3 | 0/18 | ||||||
| 11 | Runtime error | 3ms | 2376 KiB | ||||
| 12 | Accepted | 3ms | 2408 KiB | ||||
| 13 | Runtime error | 3ms | 2748 KiB | ||||
| 14 | Runtime error | 3ms | 3028 KiB | ||||
| 15 | Runtime error | 3ms | 2976 KiB | ||||
| 16 | Runtime error | 3ms | 3144 KiB | ||||
| 17 | Runtime error | 3ms | 3232 KiB | ||||
| 18 | Runtime error | 3ms | 3144 KiB | ||||
| 19 | Runtime error | 4ms | 3348 KiB | ||||
| 20 | Runtime error | 23ms | 4256 KiB | ||||
| 21 | Accepted | 28ms | 4300 KiB | ||||
| 22 | Runtime error | 23ms | 4256 KiB | ||||
| 23 | Runtime error | 23ms | 4256 KiB | ||||
| 24 | Runtime error | 23ms | 4000 KiB | ||||
| 25 | Runtime error | 23ms | 4100 KiB | ||||
| 26 | Runtime error | 23ms | 4212 KiB | ||||
| 27 | Runtime error | 23ms | 4092 KiB | ||||
| subtask4 | 0/25 | ||||||
| 28 | Runtime error | 3ms | 2376 KiB | ||||
| 29 | Accepted | 3ms | 2408 KiB | ||||
| 30 | Runtime error | 3ms | 2748 KiB | ||||
| 31 | Runtime error | 3ms | 3028 KiB | ||||
| 32 | Runtime error | 3ms | 2976 KiB | ||||
| 33 | Runtime error | 3ms | 3144 KiB | ||||
| 34 | Runtime error | 3ms | 3232 KiB | ||||
| 35 | Runtime error | 3ms | 3144 KiB | ||||
| 36 | Time limit exceeded | 1.562s | 38204 KiB | ||||
| 37 | Time limit exceeded | 1.541s | 38496 KiB | ||||
| 38 | Time limit exceeded | 1.567s | 38476 KiB | ||||
| 39 | Time limit exceeded | 1.555s | 38652 KiB | ||||
| 40 | Time limit exceeded | 1.564s | 38564 KiB | ||||
| 41 | Time limit exceeded | 1.555s | 38620 KiB | ||||
| 42 | Time limit exceeded | 1.552s | 38648 KiB | ||||
| 43 | Time limit exceeded | 1.567s | 38720 KiB | ||||
| 44 | Time limit exceeded | 1.57s | 39056 KiB | ||||
| 45 | Time limit exceeded | 1.552s | 38896 KiB | ||||
| subtask5 | 0/24 | ||||||
| 46 | Time limit exceeded | 1.555s | 39032 KiB | ||||
| 47 | Time limit exceeded | 1.572s | 38868 KiB | ||||
| 48 | Time limit exceeded | 1.536s | 38880 KiB | ||||
| 49 | Time limit exceeded | 1.58s | 38872 KiB | ||||
| 50 | Time limit exceeded | 1.557s | 39100 KiB | ||||
| 51 | Time limit exceeded | 1.574s | 39332 KiB | ||||
| 52 | Time limit exceeded | 1.56s | 39372 KiB | ||||
| 53 | Time limit exceeded | 1.601s | 39264 KiB | ||||
| 54 | Time limit exceeded | 1.582s | 39240 KiB | ||||
| 55 | Time limit exceeded | 1.552s | 39304 KiB | ||||
| subtask6 | 0/21 | ||||||
| 56 | Runtime error | 3ms | 2376 KiB | ||||
| 57 | Accepted | 3ms | 2408 KiB | ||||
| 58 | Runtime error | 3ms | 2748 KiB | ||||
| 59 | Runtime error | 3ms | 3028 KiB | ||||
| 60 | Runtime error | 3ms | 2976 KiB | ||||
| 61 | Runtime error | 3ms | 3144 KiB | ||||
| 62 | Runtime error | 3ms | 3232 KiB | ||||
| 63 | Runtime error | 3ms | 3144 KiB | ||||
| 64 | Runtime error | 4ms | 3348 KiB | ||||
| 65 | Runtime error | 23ms | 4256 KiB | ||||
| 66 | Accepted | 28ms | 4300 KiB | ||||
| 67 | Runtime error | 23ms | 4256 KiB | ||||
| 68 | Runtime error | 23ms | 4256 KiB | ||||
| 69 | Runtime error | 23ms | 4000 KiB | ||||
| 70 | Runtime error | 23ms | 4100 KiB | ||||
| 71 | Runtime error | 23ms | 4212 KiB | ||||
| 72 | Runtime error | 23ms | 4092 KiB | ||||
| 73 | Time limit exceeded | 1.562s | 38204 KiB | ||||
| 74 | Time limit exceeded | 1.541s | 38496 KiB | ||||
| 75 | Time limit exceeded | 1.567s | 38476 KiB | ||||
| 76 | Time limit exceeded | 1.555s | 38652 KiB | ||||
| 77 | Time limit exceeded | 1.564s | 38564 KiB | ||||
| 78 | Time limit exceeded | 1.555s | 38620 KiB | ||||
| 79 | Time limit exceeded | 1.552s | 38648 KiB | ||||
| 80 | Time limit exceeded | 1.567s | 38720 KiB | ||||
| 81 | Time limit exceeded | 1.57s | 39056 KiB | ||||
| 82 | Time limit exceeded | 1.552s | 38896 KiB | ||||
| 83 | Time limit exceeded | 1.555s | 39032 KiB | ||||
| 84 | Time limit exceeded | 1.572s | 38868 KiB | ||||
| 85 | Time limit exceeded | 1.536s | 38880 KiB | ||||
| 86 | Time limit exceeded | 1.58s | 38872 KiB | ||||
| 87 | Time limit exceeded | 1.557s | 39100 KiB | ||||
| 88 | Time limit exceeded | 1.574s | 39332 KiB | ||||
| 89 | Time limit exceeded | 1.56s | 39372 KiB | ||||
| 90 | Time limit exceeded | 1.601s | 39264 KiB | ||||
| 91 | Time limit exceeded | 1.582s | 39240 KiB | ||||
| 92 | Time limit exceeded | 1.552s | 39304 KiB | ||||
| 93 | Time limit exceeded | 1.572s | 39312 KiB | ||||
| 94 | Time limit exceeded | 1.546s | 39268 KiB | ||||
| 95 | Time limit exceeded | 1.526s | 39332 KiB | ||||
| 96 | Time limit exceeded | 1.562s | 39520 KiB | ||||
| 97 | Time limit exceeded | 1.546s | 39564 KiB | ||||
| 98 | Runtime error | 1.248s | 16872 KiB | ||||
| 99 | Time limit exceeded | 1.577s | 39504 KiB | ||||
| 100 | Time limit exceeded | 1.565s | 39456 KiB | ||||
| 101 | Time limit exceeded | 1.557s | 39488 KiB | ||||
| 102 | Time limit exceeded | 1.549s | 39492 KiB | ||||
| 103 | Time limit exceeded | 1.57s | 39764 KiB | ||||
| 104 | Time limit exceeded | 1.57s | 39800 KiB | ||||
| 105 | Time limit exceeded | 1.58s | 39804 KiB | ||||
| 106 | Time limit exceeded | 1.58s | 39952 KiB | ||||
| 107 | Time limit exceeded | 1.554s | 39900 KiB | ||||
| 108 | Time limit exceeded | 1.56s | 39764 KiB | ||||
| 109 | Time limit exceeded | 1.554s | 39656 KiB | ||||
| 110 | Time limit exceeded | 1.565s | 39756 KiB | ||||
| 111 | Time limit exceeded | 1.572s | 39828 KiB | ||||
| 112 | Time limit exceeded | 1.555s | 39804 KiB | ||||
| 113 | Time limit exceeded | 1.585s | 39760 KiB | ||||
| 114 | Time limit exceeded | 1.57s | 39952 KiB | ||||
| 115 | Time limit exceeded | 1.562s | 40020 KiB | ||||
| 116 | Time limit exceeded | 1.572s | 39956 KiB | ||||
| 117 | Time limit exceeded | 1.555s | 39960 KiB | ||||
| 118 | Time limit exceeded | 1.565s | 39972 KiB | ||||