답안 #208539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208539 2020-03-11T13:23:06 Z eriksuenderhauf Toll (BOI17_toll) C++11
100 / 100
350 ms 22776 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 3e5 + 5;
const double eps = 1e-9;

struct node
{
    int val[5][5];
};

node seg[MAXN];
int K;
vii adj[MAXN];

void merge(node &c, node &lC, node &rC, int a1, int a2, int a3) {
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            c.val[i][j] = INF;
            for (int k = 0; k < K; k++) {
                if (a1 == a2) k = i;
                for (pii nx: adj[a2 * K + k]) {
                    if (a2 + 1 == a3 && j != nx.fi % K) continue;
                    c.val[i][j] = min(c.val[i][j], lC.val[i][k] + rC.val[nx.fi % K][j] + nx.se);
                }
                if (a1 == a2) break;
            }
        }
    }
}

void build(int l, int r, int k) {
    if (l == r) {
        memset(seg[k].val, 0, sizeof seg[k].val);
        return;
    }
    int m = (l + r) / 2;
    build(l, m, k*2);
    build(m + 1, r, k*2 + 1);
    merge(seg[k], seg[k*2], seg[k*2 + 1], l, m, r);
}

node qry(int l, int r, int k, int a, int b) {
    if (a <= l && r <= b) return seg[k];
    int m = (l + r) / 2;
    node ret;
    if (a <= m && m < b) {
        node lC = qry(l, m, k*2, a, b);
        node rC = qry(m + 1, r, k*2 + 1, a, b);
        merge(ret, lC, rC, max(l, a), m, min(b, r));
    } else if (a <= m)
        return qry(l, m, k*2, a, b);
    else
        return qry(m + 1, r, k*2 + 1, a, b);
    return ret;
}

int main() {
    int N, M, O;
    scanf("%d %d %d %d", &K, &N, &M, &O);
    for (int i = 0; i < M; i++) {
        int a, b, t;
        scanf("%d %d %d", &a, &b, &t);
        adj[a].pb({b, t});
    }
    build(0, (N - 1) / K, 1);
    for (int i = 0; i < O; i++) {
        int a, b; scanf("%d %d", &a, &b);
        if (a / K >= b / K) {
            printf("-1\n");
            continue;
        }
        node ans = qry(0, (N - 1) / K, 1, a / K, b / K);
        int val = ans.val[a % K][b % K];
        if (val == INF) val = -1;
        printf("%d\n", val);
    }
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &K, &N, &M, &O);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &a, &b, &t);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:97:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int a, b; scanf("%d %d", &a, &b);
                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 22776 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7672 KB Output is correct
6 Correct 11 ms 7544 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 60 ms 22648 KB Output is correct
9 Correct 59 ms 22648 KB Output is correct
10 Correct 33 ms 20344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 17016 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 16 ms 7800 KB Output is correct
8 Correct 19 ms 7672 KB Output is correct
9 Correct 53 ms 22648 KB Output is correct
10 Correct 137 ms 16504 KB Output is correct
11 Correct 92 ms 17144 KB Output is correct
12 Correct 89 ms 14584 KB Output is correct
13 Correct 183 ms 14072 KB Output is correct
14 Correct 80 ms 13688 KB Output is correct
15 Correct 103 ms 11512 KB Output is correct
16 Correct 101 ms 11512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7420 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 10 ms 7544 KB Output is correct
7 Correct 10 ms 7544 KB Output is correct
8 Correct 14 ms 7548 KB Output is correct
9 Correct 12 ms 7544 KB Output is correct
10 Correct 47 ms 22520 KB Output is correct
11 Correct 61 ms 16888 KB Output is correct
12 Correct 88 ms 16376 KB Output is correct
13 Correct 106 ms 16904 KB Output is correct
14 Correct 78 ms 15608 KB Output is correct
15 Correct 68 ms 11512 KB Output is correct
16 Correct 63 ms 11640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7420 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
5 Correct 9 ms 7416 KB Output is correct
6 Correct 10 ms 7544 KB Output is correct
7 Correct 10 ms 7544 KB Output is correct
8 Correct 14 ms 7548 KB Output is correct
9 Correct 12 ms 7544 KB Output is correct
10 Correct 47 ms 22520 KB Output is correct
11 Correct 61 ms 16888 KB Output is correct
12 Correct 88 ms 16376 KB Output is correct
13 Correct 106 ms 16904 KB Output is correct
14 Correct 78 ms 15608 KB Output is correct
15 Correct 68 ms 11512 KB Output is correct
16 Correct 63 ms 11640 KB Output is correct
17 Correct 72 ms 16888 KB Output is correct
18 Correct 9 ms 7416 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7416 KB Output is correct
21 Correct 9 ms 7416 KB Output is correct
22 Correct 9 ms 7416 KB Output is correct
23 Correct 12 ms 7672 KB Output is correct
24 Correct 13 ms 7544 KB Output is correct
25 Correct 57 ms 7672 KB Output is correct
26 Correct 33 ms 7544 KB Output is correct
27 Correct 48 ms 22648 KB Output is correct
28 Correct 112 ms 16376 KB Output is correct
29 Correct 121 ms 16888 KB Output is correct
30 Correct 96 ms 15740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 22776 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7672 KB Output is correct
6 Correct 11 ms 7544 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 60 ms 22648 KB Output is correct
9 Correct 59 ms 22648 KB Output is correct
10 Correct 33 ms 20344 KB Output is correct
11 Correct 85 ms 17016 KB Output is correct
12 Correct 9 ms 7416 KB Output is correct
13 Correct 9 ms 7416 KB Output is correct
14 Correct 9 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 9 ms 7416 KB Output is correct
17 Correct 16 ms 7800 KB Output is correct
18 Correct 19 ms 7672 KB Output is correct
19 Correct 53 ms 22648 KB Output is correct
20 Correct 137 ms 16504 KB Output is correct
21 Correct 92 ms 17144 KB Output is correct
22 Correct 89 ms 14584 KB Output is correct
23 Correct 183 ms 14072 KB Output is correct
24 Correct 80 ms 13688 KB Output is correct
25 Correct 103 ms 11512 KB Output is correct
26 Correct 101 ms 11512 KB Output is correct
27 Correct 9 ms 7420 KB Output is correct
28 Correct 10 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7544 KB Output is correct
31 Correct 9 ms 7416 KB Output is correct
32 Correct 10 ms 7544 KB Output is correct
33 Correct 10 ms 7544 KB Output is correct
34 Correct 14 ms 7548 KB Output is correct
35 Correct 12 ms 7544 KB Output is correct
36 Correct 47 ms 22520 KB Output is correct
37 Correct 61 ms 16888 KB Output is correct
38 Correct 88 ms 16376 KB Output is correct
39 Correct 106 ms 16904 KB Output is correct
40 Correct 78 ms 15608 KB Output is correct
41 Correct 68 ms 11512 KB Output is correct
42 Correct 63 ms 11640 KB Output is correct
43 Correct 72 ms 16888 KB Output is correct
44 Correct 9 ms 7416 KB Output is correct
45 Correct 9 ms 7416 KB Output is correct
46 Correct 9 ms 7416 KB Output is correct
47 Correct 9 ms 7416 KB Output is correct
48 Correct 9 ms 7416 KB Output is correct
49 Correct 12 ms 7672 KB Output is correct
50 Correct 13 ms 7544 KB Output is correct
51 Correct 57 ms 7672 KB Output is correct
52 Correct 33 ms 7544 KB Output is correct
53 Correct 48 ms 22648 KB Output is correct
54 Correct 112 ms 16376 KB Output is correct
55 Correct 121 ms 16888 KB Output is correct
56 Correct 96 ms 15740 KB Output is correct
57 Correct 350 ms 16632 KB Output is correct
58 Correct 60 ms 22776 KB Output is correct
59 Correct 95 ms 17144 KB Output is correct