Submission #675053

# Submission time Handle Problem Language Result Execution time Memory
675053 2022-12-26T22:43:23 Z Trent Toll (BOI17_toll) C++17
100 / 100
238 ms 24088 KB
#include "bits/stdc++.h"
#include <cstring>
#include <fstream>

using namespace std;

#define ll long long
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define open(s) freopen(((string) s + ".in").c_str(), "r", stdin); freopen(((string) s + ".out").c_str(), "w", stdout)
#define all(i) i.begin(), i.end()
#define boost() cin.sync_with_stdio(0); cin.tie()
typedef pair<int, int> pii;

const int MN = 5e4 + 10, MK = 5, ME = 17, INF = 5e8 + 10;
struct edge{int i, w;};
int dis[MN][ME][MK];
vector<edge> adj[MN];
int k, n, m, o;

inline int st(int a){
    return k + a / k * k;
}

signed main() {
    cin >> k >> n >> m >> o;
    forR(a, MN) forR(b, ME) forR(c, MK) dis[a][b][c] = INF;

    forR(g, m){
        int a, b, t; cin >> a >> b >> t;
        dis[a][0][b - st(a)] = t;
        adj[a].push_back({b, t});
    }
    REP(e, 1, ME) forR(i, n) forR(t, k){
        dis[i][e][t] = INF;
        forR(m, k) {
            int node = k * (i / k + (1 << (e - 1))) + m;
            if(node < n) dis[i][e][t] = min(dis[i][e][t], dis[i][e-1][m] + dis[node][e-1][t]);
        }
    }
    forR(g, o){
        int a, b; cin >> a >> b;
        int amt = b / k - a / k;
        vector<int> mi(5, INF);
        mi[a % k] = 0;
        for(int c=a / k, e = ME - 1; e >= 0; --e) if((1 << e) <= amt){
            vector<int> nex(5, INF);
            forR(st, k) forR(en, k) nex[en] = min(nex[en], mi[st] + dis[k * c + st][e][en]);
            mi.swap(nex);
            c += 1 << e;
            amt -= (1 << e);
        }
        if(mi[b % k] == INF) cout << "-1\n";
        else cout << mi[b % k] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 82 ms 19704 KB Output is correct
2 Correct 9 ms 18076 KB Output is correct
3 Correct 9 ms 18004 KB Output is correct
4 Correct 11 ms 18080 KB Output is correct
5 Correct 13 ms 18140 KB Output is correct
6 Correct 13 ms 18136 KB Output is correct
7 Correct 13 ms 18132 KB Output is correct
8 Correct 88 ms 20524 KB Output is correct
9 Correct 86 ms 20452 KB Output is correct
10 Correct 40 ms 18132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 19652 KB Output is correct
2 Correct 9 ms 18012 KB Output is correct
3 Correct 8 ms 18004 KB Output is correct
4 Correct 11 ms 17996 KB Output is correct
5 Correct 9 ms 18088 KB Output is correct
6 Correct 10 ms 18004 KB Output is correct
7 Correct 30 ms 18224 KB Output is correct
8 Correct 31 ms 18272 KB Output is correct
9 Correct 81 ms 20448 KB Output is correct
10 Correct 174 ms 22832 KB Output is correct
11 Correct 135 ms 21320 KB Output is correct
12 Correct 120 ms 20828 KB Output is correct
13 Correct 160 ms 23112 KB Output is correct
14 Correct 102 ms 21168 KB Output is correct
15 Correct 106 ms 20612 KB Output is correct
16 Correct 125 ms 20580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 18004 KB Output is correct
2 Correct 9 ms 18108 KB Output is correct
3 Correct 9 ms 18004 KB Output is correct
4 Correct 9 ms 18096 KB Output is correct
5 Correct 12 ms 17992 KB Output is correct
6 Correct 10 ms 18132 KB Output is correct
7 Correct 11 ms 18132 KB Output is correct
8 Correct 14 ms 18264 KB Output is correct
9 Correct 12 ms 18180 KB Output is correct
10 Correct 64 ms 20380 KB Output is correct
11 Correct 114 ms 21168 KB Output is correct
12 Correct 155 ms 22700 KB Output is correct
13 Correct 172 ms 23148 KB Output is correct
14 Correct 139 ms 21996 KB Output is correct
15 Correct 124 ms 20508 KB Output is correct
16 Correct 93 ms 20504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 18004 KB Output is correct
2 Correct 9 ms 18108 KB Output is correct
3 Correct 9 ms 18004 KB Output is correct
4 Correct 9 ms 18096 KB Output is correct
5 Correct 12 ms 17992 KB Output is correct
6 Correct 10 ms 18132 KB Output is correct
7 Correct 11 ms 18132 KB Output is correct
8 Correct 14 ms 18264 KB Output is correct
9 Correct 12 ms 18180 KB Output is correct
10 Correct 64 ms 20380 KB Output is correct
11 Correct 114 ms 21168 KB Output is correct
12 Correct 155 ms 22700 KB Output is correct
13 Correct 172 ms 23148 KB Output is correct
14 Correct 139 ms 21996 KB Output is correct
15 Correct 124 ms 20508 KB Output is correct
16 Correct 93 ms 20504 KB Output is correct
17 Correct 118 ms 21348 KB Output is correct
18 Correct 8 ms 18004 KB Output is correct
19 Correct 9 ms 18004 KB Output is correct
20 Correct 9 ms 18004 KB Output is correct
21 Correct 9 ms 18004 KB Output is correct
22 Correct 9 ms 18004 KB Output is correct
23 Correct 16 ms 18132 KB Output is correct
24 Correct 18 ms 18132 KB Output is correct
25 Correct 19 ms 18208 KB Output is correct
26 Correct 17 ms 18132 KB Output is correct
27 Correct 74 ms 20416 KB Output is correct
28 Correct 160 ms 22732 KB Output is correct
29 Correct 171 ms 23236 KB Output is correct
30 Correct 150 ms 22032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 19704 KB Output is correct
2 Correct 9 ms 18076 KB Output is correct
3 Correct 9 ms 18004 KB Output is correct
4 Correct 11 ms 18080 KB Output is correct
5 Correct 13 ms 18140 KB Output is correct
6 Correct 13 ms 18136 KB Output is correct
7 Correct 13 ms 18132 KB Output is correct
8 Correct 88 ms 20524 KB Output is correct
9 Correct 86 ms 20452 KB Output is correct
10 Correct 40 ms 18132 KB Output is correct
11 Correct 134 ms 19652 KB Output is correct
12 Correct 9 ms 18012 KB Output is correct
13 Correct 8 ms 18004 KB Output is correct
14 Correct 11 ms 17996 KB Output is correct
15 Correct 9 ms 18088 KB Output is correct
16 Correct 10 ms 18004 KB Output is correct
17 Correct 30 ms 18224 KB Output is correct
18 Correct 31 ms 18272 KB Output is correct
19 Correct 81 ms 20448 KB Output is correct
20 Correct 174 ms 22832 KB Output is correct
21 Correct 135 ms 21320 KB Output is correct
22 Correct 120 ms 20828 KB Output is correct
23 Correct 160 ms 23112 KB Output is correct
24 Correct 102 ms 21168 KB Output is correct
25 Correct 106 ms 20612 KB Output is correct
26 Correct 125 ms 20580 KB Output is correct
27 Correct 9 ms 18004 KB Output is correct
28 Correct 9 ms 18108 KB Output is correct
29 Correct 9 ms 18004 KB Output is correct
30 Correct 9 ms 18096 KB Output is correct
31 Correct 12 ms 17992 KB Output is correct
32 Correct 10 ms 18132 KB Output is correct
33 Correct 11 ms 18132 KB Output is correct
34 Correct 14 ms 18264 KB Output is correct
35 Correct 12 ms 18180 KB Output is correct
36 Correct 64 ms 20380 KB Output is correct
37 Correct 114 ms 21168 KB Output is correct
38 Correct 155 ms 22700 KB Output is correct
39 Correct 172 ms 23148 KB Output is correct
40 Correct 139 ms 21996 KB Output is correct
41 Correct 124 ms 20508 KB Output is correct
42 Correct 93 ms 20504 KB Output is correct
43 Correct 118 ms 21348 KB Output is correct
44 Correct 8 ms 18004 KB Output is correct
45 Correct 9 ms 18004 KB Output is correct
46 Correct 9 ms 18004 KB Output is correct
47 Correct 9 ms 18004 KB Output is correct
48 Correct 9 ms 18004 KB Output is correct
49 Correct 16 ms 18132 KB Output is correct
50 Correct 18 ms 18132 KB Output is correct
51 Correct 19 ms 18208 KB Output is correct
52 Correct 17 ms 18132 KB Output is correct
53 Correct 74 ms 20416 KB Output is correct
54 Correct 160 ms 22732 KB Output is correct
55 Correct 171 ms 23236 KB Output is correct
56 Correct 150 ms 22032 KB Output is correct
57 Correct 238 ms 24088 KB Output is correct
58 Correct 85 ms 20696 KB Output is correct
59 Correct 158 ms 21376 KB Output is correct