Submission #1097402

# Submission time Handle Problem Language Result Execution time Memory
1097402 2024-10-07T08:22:04 Z vjudge1 Construction Project 2 (JOI24_ho_t2) C++17
100 / 100
298 ms 32608 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)


constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
    Phu Trong from Nguyen Tat Thanh High School for gifted student
*/

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
#define MAX                         200005
int numNode, numEdge;
int from, to, length, minTime;

struct Edge{
    int u, v, w;
    Edge(){}
    Edge(int _u, int _v, int _w): u(_u), v(_v), w(_w){}

    int other(int x){
        return (x ^ u ^ v);
    }
} edge[MAX];
vector<int> G[MAX];

void dijkstra(int s, int minDist[]){
    for (int i = 1; i <= numNode; ++i) minDist[i] = LINF;
    minDist[s] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.emplace(0, s);
    while(q.size()){
        int du, u; tie(du, u) = q.top();
        q.pop();
        if (du > minDist[u]) continue;
        for (int&i : G[u]){
            int v = edge[i].other(u);
            if(minimize(minDist[v], minDist[u] + edge[i].w)){
                q.emplace(minDist[v], v);
            }
        }
    }
}
int minDist[2][MAX];
vector<int> comp;
struct FenwickTree{
    vector<int> F;
    int n;
    FenwickTree(int _n = 0){
        this -> n = _n;
        F.resize(n + 5, 0);
    }
    int low_bit(int p){
        return p & -p;
    }
    void upd(int p, int v){
        for (; p <= n; p += low_bit(p)) F[p] += v;
    }
    int query(int p){
        int res = 0;
        for (; p > 0; p -= low_bit(p)) res += F[p];
        return res;
    }
};
int find(int x){
    return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1;
}

void process(void){
    cin >> numNode >> numEdge >> from >> to;
    cin >> length >> minTime;
    //build a new road with length l
    //move from s -> t and does not exceed minTime

    //D(from, u) + l + D(v, to) <= minTime
    //-> D(from, u) <= minTime - l - D(v, to)
    for (int i = 1; i <= numEdge; ++i){
        cin >> edge[i].u >> edge[i].v >> edge[i].w;
        G[edge[i].u].emplace_back(i);
        G[edge[i].v].emplace_back(i);
    }

    dijkstra(from, minDist[0]);
    dijkstra(to,   minDist[1]);

    if(minDist[0][to] <= minTime){
        return void(cout << numNode * (numNode - 1) / 2);
    }

    for (int i = 1; i <= numNode; ++i){
        comp.emplace_back(minDist[0][i]);
        comp.emplace_back(minTime - minDist[1][i] - length);
    }
    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
    FenwickTree ft((int)comp.size());

    for (int i = 1; i <= numNode; ++i){
        int value = find(minDist[0][i]);
        ft.upd(value, 1);
    }
    int ans = 0;
    for (int i = 1; i <= numNode; ++i){
        int prv = find(minDist[0][i]);
        int value = find(minTime - minDist[1][i] - length);

        ft.upd(prv, -1);
        ans += ft.query(value);
        ft.upd(prv, 1);
    }
    cout << ans;
}
signed main(){
    #define name "Whisper"
    cin.tie(nullptr) -> sync_with_stdio(false);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    process();
    return (0 ^ 0);
}




# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5468 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 66 ms 26604 KB Output is correct
8 Correct 73 ms 26716 KB Output is correct
9 Correct 62 ms 24500 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 4 ms 5468 KB Output is correct
14 Correct 41 ms 20428 KB Output is correct
15 Correct 144 ms 27144 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 5468 KB Output is correct
18 Correct 97 ms 27072 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5440 KB Output is correct
22 Correct 4 ms 5464 KB Output is correct
23 Correct 42 ms 20424 KB Output is correct
24 Correct 146 ms 27144 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 5468 KB Output is correct
27 Correct 73 ms 30888 KB Output is correct
28 Correct 58 ms 22172 KB Output is correct
29 Correct 79 ms 24004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5176 KB Output is correct
4 Correct 2 ms 5044 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4988 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 5152 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 5180 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 5176 KB Output is correct
4 Correct 2 ms 5044 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4988 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 5152 KB Output is correct
23 Correct 2 ms 4952 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 5180 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 4952 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 3 ms 5720 KB Output is correct
34 Correct 3 ms 5468 KB Output is correct
35 Correct 3 ms 5468 KB Output is correct
36 Correct 4 ms 5324 KB Output is correct
37 Correct 3 ms 5464 KB Output is correct
38 Correct 3 ms 5468 KB Output is correct
39 Correct 4 ms 5468 KB Output is correct
40 Correct 3 ms 5468 KB Output is correct
41 Correct 3 ms 5212 KB Output is correct
42 Correct 3 ms 5440 KB Output is correct
43 Correct 4 ms 5448 KB Output is correct
44 Correct 4 ms 5468 KB Output is correct
45 Correct 4 ms 5468 KB Output is correct
46 Correct 5 ms 5468 KB Output is correct
47 Correct 4 ms 5468 KB Output is correct
48 Correct 4 ms 5520 KB Output is correct
49 Correct 3 ms 5212 KB Output is correct
50 Correct 3 ms 5468 KB Output is correct
51 Correct 5 ms 5324 KB Output is correct
52 Correct 4 ms 5468 KB Output is correct
53 Correct 4 ms 5468 KB Output is correct
54 Correct 4 ms 5444 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 3 ms 5212 KB Output is correct
57 Correct 4 ms 5212 KB Output is correct
58 Correct 4 ms 5440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5468 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 66 ms 26604 KB Output is correct
8 Correct 73 ms 26716 KB Output is correct
9 Correct 62 ms 24500 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 4 ms 5468 KB Output is correct
14 Correct 41 ms 20428 KB Output is correct
15 Correct 144 ms 27144 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 3 ms 5468 KB Output is correct
18 Correct 97 ms 27072 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 5440 KB Output is correct
22 Correct 4 ms 5464 KB Output is correct
23 Correct 42 ms 20424 KB Output is correct
24 Correct 146 ms 27144 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 3 ms 5468 KB Output is correct
27 Correct 73 ms 30888 KB Output is correct
28 Correct 58 ms 22172 KB Output is correct
29 Correct 79 ms 24004 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 5176 KB Output is correct
33 Correct 2 ms 5044 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 3 ms 4952 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 3 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4952 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4988 KB Output is correct
46 Correct 2 ms 4952 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 3 ms 4956 KB Output is correct
51 Correct 3 ms 5152 KB Output is correct
52 Correct 2 ms 4952 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 5180 KB Output is correct
56 Correct 2 ms 5208 KB Output is correct
57 Correct 2 ms 4952 KB Output is correct
58 Correct 2 ms 4956 KB Output is correct
59 Correct 2 ms 4956 KB Output is correct
60 Correct 2 ms 4956 KB Output is correct
61 Correct 2 ms 4956 KB Output is correct
62 Correct 3 ms 5720 KB Output is correct
63 Correct 3 ms 5468 KB Output is correct
64 Correct 3 ms 5468 KB Output is correct
65 Correct 4 ms 5324 KB Output is correct
66 Correct 3 ms 5464 KB Output is correct
67 Correct 3 ms 5468 KB Output is correct
68 Correct 4 ms 5468 KB Output is correct
69 Correct 3 ms 5468 KB Output is correct
70 Correct 3 ms 5212 KB Output is correct
71 Correct 3 ms 5440 KB Output is correct
72 Correct 4 ms 5448 KB Output is correct
73 Correct 4 ms 5468 KB Output is correct
74 Correct 4 ms 5468 KB Output is correct
75 Correct 5 ms 5468 KB Output is correct
76 Correct 4 ms 5468 KB Output is correct
77 Correct 4 ms 5520 KB Output is correct
78 Correct 3 ms 5212 KB Output is correct
79 Correct 3 ms 5468 KB Output is correct
80 Correct 5 ms 5324 KB Output is correct
81 Correct 4 ms 5468 KB Output is correct
82 Correct 4 ms 5468 KB Output is correct
83 Correct 4 ms 5444 KB Output is correct
84 Correct 3 ms 5212 KB Output is correct
85 Correct 3 ms 5212 KB Output is correct
86 Correct 4 ms 5212 KB Output is correct
87 Correct 4 ms 5440 KB Output is correct
88 Correct 89 ms 24880 KB Output is correct
89 Correct 102 ms 24884 KB Output is correct
90 Correct 96 ms 28840 KB Output is correct
91 Correct 44 ms 18772 KB Output is correct
92 Correct 49 ms 18956 KB Output is correct
93 Correct 48 ms 21208 KB Output is correct
94 Correct 47 ms 21192 KB Output is correct
95 Correct 298 ms 30116 KB Output is correct
96 Correct 165 ms 25796 KB Output is correct
97 Correct 229 ms 29876 KB Output is correct
98 Correct 221 ms 29848 KB Output is correct
99 Correct 101 ms 30040 KB Output is correct
100 Correct 99 ms 29912 KB Output is correct
101 Correct 40 ms 18772 KB Output is correct
102 Correct 40 ms 18772 KB Output is correct
103 Correct 47 ms 21204 KB Output is correct
104 Correct 50 ms 21188 KB Output is correct
105 Correct 279 ms 30144 KB Output is correct
106 Correct 248 ms 30168 KB Output is correct
107 Correct 272 ms 32312 KB Output is correct
108 Correct 278 ms 32608 KB Output is correct
109 Correct 87 ms 23264 KB Output is correct
110 Correct 88 ms 23288 KB Output is correct
111 Correct 112 ms 24608 KB Output is correct
112 Correct 113 ms 24276 KB Output is correct