# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
381693 |
2021-03-25T16:59:07 Z |
peijar |
Toll (BOI17_toll) |
C++17 |
|
168 ms |
157164 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 5e4;
const int MAXP = 16;
const int INF = 2e18;
int mod, nbSommets, nbAretes, nbRequetes;
int dis[MAXP][MAXN][5][5];
signed main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> mod >> nbSommets >> nbAretes >> nbRequetes;
for (int p(0); p < MAXP; ++p)
for (int iSommet(0); iSommet < MAXN; ++iSommet)
for (int iDep(0); iDep < mod; ++iDep)
for (int iFin(0); iFin < mod; ++iFin)
dis[p][iSommet][iDep][iFin] = INF;
while (nbAretes--)
{
int u, v, c;
cin >> u >> v >> c;
dis[0][u/mod][u%mod][v%mod] = c;
}
for (int p(1); p < MAXP; ++p)
for (int iSommet(0); iSommet + (1 << (p-1))< (nbSommets+mod-1)/mod; ++iSommet)
for (int iDep(0); iDep < mod; ++iDep)
for (int iFin(0); iFin < mod; ++iFin)
for (int iMilieu(0); iMilieu < mod; ++iMilieu)
dis[p][iSommet][iDep][iFin] = min(dis[p][iSommet][iDep][iFin],
dis[p-1][iSommet][iDep][iMilieu] + dis[p-1][iSommet + (1<<(p-1))][iMilieu][iFin]);
array<int, 5> cur, nxt;
for (int iRequete = 0; iRequete < nbRequetes; ++iRequete)
{
int from, to;
cin >> from >> to;
int diff = to/mod - from/mod;
fill(cur.begin(), cur.end(), INF);
fill(nxt.begin(), nxt.end(), INF);
cur[from%mod] = 0;
int curPos = from/mod;
for (int p(0); p < MAXP; ++p)
if ((1<<p) & diff)
{
for (int iDep(0); iDep < mod; ++iDep)
for (int iFin(0); iFin < mod; ++iFin)
nxt[iFin] = min(nxt[iFin],
cur[iDep] + dis[p][curPos][iDep][iFin]);
curPos += 1 << p;
cur = move(nxt);
fill(nxt.begin(), nxt.end(), INF);
}
int ret = cur[to%mod];
if (ret == INF) ret = -1;
cout << ret << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
157036 KB |
Output is correct |
2 |
Correct |
68 ms |
156908 KB |
Output is correct |
3 |
Correct |
68 ms |
157036 KB |
Output is correct |
4 |
Correct |
68 ms |
156908 KB |
Output is correct |
5 |
Correct |
70 ms |
156908 KB |
Output is correct |
6 |
Correct |
69 ms |
156908 KB |
Output is correct |
7 |
Correct |
70 ms |
156928 KB |
Output is correct |
8 |
Correct |
123 ms |
156952 KB |
Output is correct |
9 |
Correct |
114 ms |
156908 KB |
Output is correct |
10 |
Correct |
99 ms |
157036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
157008 KB |
Output is correct |
2 |
Correct |
73 ms |
156908 KB |
Output is correct |
3 |
Correct |
72 ms |
156908 KB |
Output is correct |
4 |
Correct |
74 ms |
156908 KB |
Output is correct |
5 |
Correct |
77 ms |
156924 KB |
Output is correct |
6 |
Correct |
81 ms |
156908 KB |
Output is correct |
7 |
Correct |
75 ms |
156908 KB |
Output is correct |
8 |
Correct |
76 ms |
156908 KB |
Output is correct |
9 |
Correct |
113 ms |
156908 KB |
Output is correct |
10 |
Correct |
135 ms |
157036 KB |
Output is correct |
11 |
Correct |
121 ms |
157164 KB |
Output is correct |
12 |
Correct |
112 ms |
156908 KB |
Output is correct |
13 |
Correct |
138 ms |
156908 KB |
Output is correct |
14 |
Correct |
109 ms |
156908 KB |
Output is correct |
15 |
Correct |
116 ms |
156908 KB |
Output is correct |
16 |
Correct |
116 ms |
157036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
157036 KB |
Output is correct |
2 |
Correct |
71 ms |
157036 KB |
Output is correct |
3 |
Correct |
74 ms |
156908 KB |
Output is correct |
4 |
Correct |
77 ms |
156908 KB |
Output is correct |
5 |
Correct |
81 ms |
156908 KB |
Output is correct |
6 |
Correct |
72 ms |
156908 KB |
Output is correct |
7 |
Correct |
71 ms |
156908 KB |
Output is correct |
8 |
Correct |
85 ms |
156908 KB |
Output is correct |
9 |
Correct |
78 ms |
156908 KB |
Output is correct |
10 |
Correct |
110 ms |
157036 KB |
Output is correct |
11 |
Correct |
115 ms |
157036 KB |
Output is correct |
12 |
Correct |
126 ms |
156908 KB |
Output is correct |
13 |
Correct |
129 ms |
156908 KB |
Output is correct |
14 |
Correct |
119 ms |
156908 KB |
Output is correct |
15 |
Correct |
115 ms |
157036 KB |
Output is correct |
16 |
Correct |
114 ms |
156908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
157036 KB |
Output is correct |
2 |
Correct |
71 ms |
157036 KB |
Output is correct |
3 |
Correct |
74 ms |
156908 KB |
Output is correct |
4 |
Correct |
77 ms |
156908 KB |
Output is correct |
5 |
Correct |
81 ms |
156908 KB |
Output is correct |
6 |
Correct |
72 ms |
156908 KB |
Output is correct |
7 |
Correct |
71 ms |
156908 KB |
Output is correct |
8 |
Correct |
85 ms |
156908 KB |
Output is correct |
9 |
Correct |
78 ms |
156908 KB |
Output is correct |
10 |
Correct |
110 ms |
157036 KB |
Output is correct |
11 |
Correct |
115 ms |
157036 KB |
Output is correct |
12 |
Correct |
126 ms |
156908 KB |
Output is correct |
13 |
Correct |
129 ms |
156908 KB |
Output is correct |
14 |
Correct |
119 ms |
156908 KB |
Output is correct |
15 |
Correct |
115 ms |
157036 KB |
Output is correct |
16 |
Correct |
114 ms |
156908 KB |
Output is correct |
17 |
Correct |
120 ms |
156908 KB |
Output is correct |
18 |
Correct |
70 ms |
156908 KB |
Output is correct |
19 |
Correct |
72 ms |
156908 KB |
Output is correct |
20 |
Correct |
74 ms |
156924 KB |
Output is correct |
21 |
Correct |
77 ms |
156908 KB |
Output is correct |
22 |
Correct |
91 ms |
156908 KB |
Output is correct |
23 |
Correct |
71 ms |
156908 KB |
Output is correct |
24 |
Correct |
74 ms |
157036 KB |
Output is correct |
25 |
Correct |
85 ms |
156908 KB |
Output is correct |
26 |
Correct |
79 ms |
156908 KB |
Output is correct |
27 |
Correct |
109 ms |
156908 KB |
Output is correct |
28 |
Correct |
132 ms |
156908 KB |
Output is correct |
29 |
Correct |
136 ms |
156952 KB |
Output is correct |
30 |
Correct |
124 ms |
156908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
157036 KB |
Output is correct |
2 |
Correct |
68 ms |
156908 KB |
Output is correct |
3 |
Correct |
68 ms |
157036 KB |
Output is correct |
4 |
Correct |
68 ms |
156908 KB |
Output is correct |
5 |
Correct |
70 ms |
156908 KB |
Output is correct |
6 |
Correct |
69 ms |
156908 KB |
Output is correct |
7 |
Correct |
70 ms |
156928 KB |
Output is correct |
8 |
Correct |
123 ms |
156952 KB |
Output is correct |
9 |
Correct |
114 ms |
156908 KB |
Output is correct |
10 |
Correct |
99 ms |
157036 KB |
Output is correct |
11 |
Correct |
117 ms |
157008 KB |
Output is correct |
12 |
Correct |
73 ms |
156908 KB |
Output is correct |
13 |
Correct |
72 ms |
156908 KB |
Output is correct |
14 |
Correct |
74 ms |
156908 KB |
Output is correct |
15 |
Correct |
77 ms |
156924 KB |
Output is correct |
16 |
Correct |
81 ms |
156908 KB |
Output is correct |
17 |
Correct |
75 ms |
156908 KB |
Output is correct |
18 |
Correct |
76 ms |
156908 KB |
Output is correct |
19 |
Correct |
113 ms |
156908 KB |
Output is correct |
20 |
Correct |
135 ms |
157036 KB |
Output is correct |
21 |
Correct |
121 ms |
157164 KB |
Output is correct |
22 |
Correct |
112 ms |
156908 KB |
Output is correct |
23 |
Correct |
138 ms |
156908 KB |
Output is correct |
24 |
Correct |
109 ms |
156908 KB |
Output is correct |
25 |
Correct |
116 ms |
156908 KB |
Output is correct |
26 |
Correct |
116 ms |
157036 KB |
Output is correct |
27 |
Correct |
69 ms |
157036 KB |
Output is correct |
28 |
Correct |
71 ms |
157036 KB |
Output is correct |
29 |
Correct |
74 ms |
156908 KB |
Output is correct |
30 |
Correct |
77 ms |
156908 KB |
Output is correct |
31 |
Correct |
81 ms |
156908 KB |
Output is correct |
32 |
Correct |
72 ms |
156908 KB |
Output is correct |
33 |
Correct |
71 ms |
156908 KB |
Output is correct |
34 |
Correct |
85 ms |
156908 KB |
Output is correct |
35 |
Correct |
78 ms |
156908 KB |
Output is correct |
36 |
Correct |
110 ms |
157036 KB |
Output is correct |
37 |
Correct |
115 ms |
157036 KB |
Output is correct |
38 |
Correct |
126 ms |
156908 KB |
Output is correct |
39 |
Correct |
129 ms |
156908 KB |
Output is correct |
40 |
Correct |
119 ms |
156908 KB |
Output is correct |
41 |
Correct |
115 ms |
157036 KB |
Output is correct |
42 |
Correct |
114 ms |
156908 KB |
Output is correct |
43 |
Correct |
120 ms |
156908 KB |
Output is correct |
44 |
Correct |
70 ms |
156908 KB |
Output is correct |
45 |
Correct |
72 ms |
156908 KB |
Output is correct |
46 |
Correct |
74 ms |
156924 KB |
Output is correct |
47 |
Correct |
77 ms |
156908 KB |
Output is correct |
48 |
Correct |
91 ms |
156908 KB |
Output is correct |
49 |
Correct |
71 ms |
156908 KB |
Output is correct |
50 |
Correct |
74 ms |
157036 KB |
Output is correct |
51 |
Correct |
85 ms |
156908 KB |
Output is correct |
52 |
Correct |
79 ms |
156908 KB |
Output is correct |
53 |
Correct |
109 ms |
156908 KB |
Output is correct |
54 |
Correct |
132 ms |
156908 KB |
Output is correct |
55 |
Correct |
136 ms |
156952 KB |
Output is correct |
56 |
Correct |
124 ms |
156908 KB |
Output is correct |
57 |
Correct |
168 ms |
157036 KB |
Output is correct |
58 |
Correct |
117 ms |
157036 KB |
Output is correct |
59 |
Correct |
126 ms |
157036 KB |
Output is correct |