Submission #830639

# Submission time Handle Problem Language Result Execution time Memory
830639 2023-08-19T08:47:36 Z Johann Toll (BOI17_toll) C++14
100 / 100
2464 ms 8784 KB
// Gets sub1-sub4 with more or less naive approach
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define vb vector<bool>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define vvpii vector<vpii>
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define F0R(i,n) for (int i = 0; i < (n); ++i)

const int MAXN = 50005;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int k,n,m,o;
    cin >> k >> n >> m >> o;
    vvpii adj(n);
    F0R(i,m) {
        int a,b,t;
        cin >> a >> b >> t;
        adj[a].push_back({b,t});
    }
    vi ans(o, -1);
    vvpii orders(n);
    F0R(i,o) {
        int a,b;
        cin >> a >> b;
        if (a <= b)
            orders[a].push_back({ b, i });
    }
    F0R(i,n) { sort(all(orders[i])); reverse(all(orders[i])); }

    F0R(a,n) {
        int first = a;
        vi buffer(2*k+1, INT_MAX);
        buffer[0] = 0;
        while (sz(orders[a]) > 0) {
            if (first == orders[a].back().first) {
                ans[orders[a].back().second] = (buffer[0] == INT_MAX) ? -1 : buffer[0];
                orders[a].pop_back();
            } else {
                if (buffer[0] != INT_MAX) {
                    for (pii e : adj[first]) {
                        auto [u, t] = e;
                        buffer[u - first] = min(buffer[u-first], buffer[0] + t);
                    }
                }
                for (int i = 0; i < sz(buffer)-1; ++i) swap(buffer[i], buffer[i+1]);
                buffer.back() = INT_MAX;
                ++first;
            }
        }
    }

    for (int x : ans) cout << x << "\n";
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:51:30: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |                         auto [u, t] = e;
      |                              ^
# Verdict Execution time Memory Grader output
1 Correct 1091 ms 5460 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 322 ms 5456 KB Output is correct
9 Correct 297 ms 5352 KB Output is correct
10 Correct 284 ms 3108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 6092 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 716 KB Output is correct
9 Correct 16 ms 5332 KB Output is correct
10 Correct 36 ms 7668 KB Output is correct
11 Correct 27 ms 6368 KB Output is correct
12 Correct 21 ms 5580 KB Output is correct
13 Correct 38 ms 6912 KB Output is correct
14 Correct 23 ms 4904 KB Output is correct
15 Correct 21 ms 4280 KB Output is correct
16 Correct 20 ms 4340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 17 ms 4996 KB Output is correct
11 Correct 40 ms 5708 KB Output is correct
12 Correct 55 ms 7244 KB Output is correct
13 Correct 63 ms 7752 KB Output is correct
14 Correct 56 ms 6560 KB Output is correct
15 Correct 36 ms 4180 KB Output is correct
16 Correct 33 ms 4132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 17 ms 4996 KB Output is correct
11 Correct 40 ms 5708 KB Output is correct
12 Correct 55 ms 7244 KB Output is correct
13 Correct 63 ms 7752 KB Output is correct
14 Correct 56 ms 6560 KB Output is correct
15 Correct 36 ms 4180 KB Output is correct
16 Correct 33 ms 4132 KB Output is correct
17 Correct 508 ms 5884 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 2 ms 464 KB Output is correct
24 Correct 4 ms 540 KB Output is correct
25 Correct 7 ms 472 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 113 ms 5088 KB Output is correct
28 Correct 702 ms 7356 KB Output is correct
29 Correct 690 ms 7864 KB Output is correct
30 Correct 534 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1091 ms 5460 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 322 ms 5456 KB Output is correct
9 Correct 297 ms 5352 KB Output is correct
10 Correct 284 ms 3108 KB Output is correct
11 Correct 26 ms 6092 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 16 ms 5332 KB Output is correct
20 Correct 36 ms 7668 KB Output is correct
21 Correct 27 ms 6368 KB Output is correct
22 Correct 21 ms 5580 KB Output is correct
23 Correct 38 ms 6912 KB Output is correct
24 Correct 23 ms 4904 KB Output is correct
25 Correct 21 ms 4280 KB Output is correct
26 Correct 20 ms 4340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 17 ms 4996 KB Output is correct
37 Correct 40 ms 5708 KB Output is correct
38 Correct 55 ms 7244 KB Output is correct
39 Correct 63 ms 7752 KB Output is correct
40 Correct 56 ms 6560 KB Output is correct
41 Correct 36 ms 4180 KB Output is correct
42 Correct 33 ms 4132 KB Output is correct
43 Correct 508 ms 5884 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 2 ms 464 KB Output is correct
50 Correct 4 ms 540 KB Output is correct
51 Correct 7 ms 472 KB Output is correct
52 Correct 6 ms 468 KB Output is correct
53 Correct 113 ms 5088 KB Output is correct
54 Correct 702 ms 7356 KB Output is correct
55 Correct 690 ms 7864 KB Output is correct
56 Correct 534 ms 6604 KB Output is correct
57 Correct 2464 ms 8784 KB Output is correct
58 Correct 350 ms 5460 KB Output is correct
59 Correct 1512 ms 6268 KB Output is correct