10810 | 2024-04-15 11:08:02 | Ablablabla | Autó-tortúra | cpp17 | Time limit exceeded 0/100 | 1.6s | 40032 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 = (tav[latogat[ind]][latogat[ind + 1]] <= tank ? megold(ind + 1, tank - tav[latogat[ind]][latogat[ind + 1]]) : INF);
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 = (mini != INF ? megold(ind + 1, k - mini) + k - (tank - tav[latogat[ind]][minInd]) : INF);
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++){
if(tav[i][l] == INF || tav[l][j] == INF) continue;
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));
int a = megold(0, k) + k;
if(a >= INF){
cout << "-1\n";
} else{
cout << a << "\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1680 KiB | ||||
2 | Time limit exceeded | 1.6s | 20652 KiB | ||||
subtask2 | 0/12 | ||||||
3 | Accepted | 3ms | 2060 KiB | ||||
4 | Wrong answer | 3ms | 2272 KiB | ||||
5 | Accepted | 3ms | 2512 KiB | ||||
6 | Wrong answer | 3ms | 2620 KiB | ||||
7 | Wrong answer | 3ms | 2820 KiB | ||||
8 | Wrong answer | 3ms | 3076 KiB | ||||
9 | Wrong answer | 3ms | 3196 KiB | ||||
10 | Accepted | 3ms | 3224 KiB | ||||
subtask3 | 0/18 | ||||||
11 | Accepted | 3ms | 2060 KiB | ||||
12 | Wrong answer | 3ms | 2272 KiB | ||||
13 | Accepted | 3ms | 2512 KiB | ||||
14 | Wrong answer | 3ms | 2620 KiB | ||||
15 | Wrong answer | 3ms | 2820 KiB | ||||
16 | Wrong answer | 3ms | 3076 KiB | ||||
17 | Wrong answer | 3ms | 3196 KiB | ||||
18 | Accepted | 3ms | 3224 KiB | ||||
19 | Wrong answer | 4ms | 3548 KiB | ||||
20 | Wrong answer | 35ms | 4608 KiB | ||||
21 | Accepted | 39ms | 4692 KiB | ||||
22 | Wrong answer | 29ms | 4824 KiB | ||||
23 | Wrong answer | 26ms | 5068 KiB | ||||
24 | Wrong answer | 25ms | 4488 KiB | ||||
25 | Wrong answer | 25ms | 4632 KiB | ||||
26 | Wrong answer | 25ms | 4812 KiB | ||||
27 | Wrong answer | 24ms | 4888 KiB | ||||
subtask4 | 0/25 | ||||||
28 | Accepted | 3ms | 2060 KiB | ||||
29 | Wrong answer | 3ms | 2272 KiB | ||||
30 | Accepted | 3ms | 2512 KiB | ||||
31 | Wrong answer | 3ms | 2620 KiB | ||||
32 | Wrong answer | 3ms | 2820 KiB | ||||
33 | Wrong answer | 3ms | 3076 KiB | ||||
34 | Wrong answer | 3ms | 3196 KiB | ||||
35 | Accepted | 3ms | 3224 KiB | ||||
36 | Time limit exceeded | 1.552s | 38996 KiB | ||||
37 | Time limit exceeded | 1.577s | 38976 KiB | ||||
38 | Time limit exceeded | 1.559s | 39300 KiB | ||||
39 | Time limit exceeded | 1.574s | 39340 KiB | ||||
40 | Time limit exceeded | 1.569s | 39208 KiB | ||||
41 | Time limit exceeded | 1.569s | 39208 KiB | ||||
42 | Time limit exceeded | 1.555s | 39208 KiB | ||||
43 | Time limit exceeded | 1.555s | 39172 KiB | ||||
44 | Time limit exceeded | 1.577s | 39440 KiB | ||||
45 | Time limit exceeded | 1.564s | 39340 KiB | ||||
subtask5 | 0/24 | ||||||
46 | Time limit exceeded | 1.575s | 39348 KiB | ||||
47 | Time limit exceeded | 1.57s | 39504 KiB | ||||
48 | Time limit exceeded | 1.562s | 39600 KiB | ||||
49 | Time limit exceeded | 1.58s | 39344 KiB | ||||
50 | Time limit exceeded | 1.552s | 39384 KiB | ||||
51 | Time limit exceeded | 1.572s | 39440 KiB | ||||
52 | Time limit exceeded | 1.575s | 39500 KiB | ||||
53 | Time limit exceeded | 1.582s | 39448 KiB | ||||
54 | Time limit exceeded | 1.569s | 39744 KiB | ||||
55 | Time limit exceeded | 1.564s | 39672 KiB | ||||
subtask6 | 0/21 | ||||||
56 | Accepted | 3ms | 2060 KiB | ||||
57 | Wrong answer | 3ms | 2272 KiB | ||||
58 | Accepted | 3ms | 2512 KiB | ||||
59 | Wrong answer | 3ms | 2620 KiB | ||||
60 | Wrong answer | 3ms | 2820 KiB | ||||
61 | Wrong answer | 3ms | 3076 KiB | ||||
62 | Wrong answer | 3ms | 3196 KiB | ||||
63 | Accepted | 3ms | 3224 KiB | ||||
64 | Wrong answer | 4ms | 3548 KiB | ||||
65 | Wrong answer | 35ms | 4608 KiB | ||||
66 | Accepted | 39ms | 4692 KiB | ||||
67 | Wrong answer | 29ms | 4824 KiB | ||||
68 | Wrong answer | 26ms | 5068 KiB | ||||
69 | Wrong answer | 25ms | 4488 KiB | ||||
70 | Wrong answer | 25ms | 4632 KiB | ||||
71 | Wrong answer | 25ms | 4812 KiB | ||||
72 | Wrong answer | 24ms | 4888 KiB | ||||
73 | Time limit exceeded | 1.552s | 38996 KiB | ||||
74 | Time limit exceeded | 1.577s | 38976 KiB | ||||
75 | Time limit exceeded | 1.559s | 39300 KiB | ||||
76 | Time limit exceeded | 1.574s | 39340 KiB | ||||
77 | Time limit exceeded | 1.569s | 39208 KiB | ||||
78 | Time limit exceeded | 1.569s | 39208 KiB | ||||
79 | Time limit exceeded | 1.555s | 39208 KiB | ||||
80 | Time limit exceeded | 1.555s | 39172 KiB | ||||
81 | Time limit exceeded | 1.577s | 39440 KiB | ||||
82 | Time limit exceeded | 1.564s | 39340 KiB | ||||
83 | Time limit exceeded | 1.575s | 39348 KiB | ||||
84 | Time limit exceeded | 1.57s | 39504 KiB | ||||
85 | Time limit exceeded | 1.562s | 39600 KiB | ||||
86 | Time limit exceeded | 1.58s | 39344 KiB | ||||
87 | Time limit exceeded | 1.552s | 39384 KiB | ||||
88 | Time limit exceeded | 1.572s | 39440 KiB | ||||
89 | Time limit exceeded | 1.575s | 39500 KiB | ||||
90 | Time limit exceeded | 1.582s | 39448 KiB | ||||
91 | Time limit exceeded | 1.569s | 39744 KiB | ||||
92 | Time limit exceeded | 1.564s | 39672 KiB | ||||
93 | Time limit exceeded | 1.585s | 39488 KiB | ||||
94 | Time limit exceeded | 1.555s | 39892 KiB | ||||
95 | Time limit exceeded | 1.59s | 39888 KiB | ||||
96 | Time limit exceeded | 1.557s | 39812 KiB | ||||
97 | Time limit exceeded | 1.555s | 39828 KiB | ||||
98 | Time limit exceeded | 1.562s | 8300 KiB | ||||
99 | Time limit exceeded | 1.57s | 40028 KiB | ||||
100 | Time limit exceeded | 1.562s | 39832 KiB | ||||
101 | Time limit exceeded | 1.577s | 39876 KiB | ||||
102 | Time limit exceeded | 1.565s | 39872 KiB | ||||
103 | Time limit exceeded | 1.557s | 39816 KiB | ||||
104 | Time limit exceeded | 1.56s | 39892 KiB | ||||
105 | Time limit exceeded | 1.577s | 39976 KiB | ||||
106 | Time limit exceeded | 1.569s | 39972 KiB | ||||
107 | Time limit exceeded | 1.569s | 39912 KiB | ||||
108 | Time limit exceeded | 1.58s | 40032 KiB | ||||
109 | Time limit exceeded | 1.56s | 39880 KiB | ||||
110 | Time limit exceeded | 1.559s | 39952 KiB | ||||
111 | Time limit exceeded | 1.572s | 40016 KiB | ||||
112 | Time limit exceeded | 1.555s | 39996 KiB | ||||
113 | Time limit exceeded | 1.572s | 39908 KiB | ||||
114 | Time limit exceeded | 1.58s | 39900 KiB | ||||
115 | Time limit exceeded | 1.572s | 39888 KiB | ||||
116 | Time limit exceeded | 1.577s | 39876 KiB | ||||
117 | Time limit exceeded | 1.58s | 40024 KiB | ||||
118 | Time limit exceeded | 1.567s | 39968 KiB |