# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109619 |
2024-11-07T07:31:59 Z |
vjudge1 |
Toll (BOI17_toll) |
C++17 |
|
2847 ms |
7352 KB |
#include <bits/stdc++.h>
/*
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
*/
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define F first
#define S second
#define pb push_back
#define FIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
#define md(a) ((a%mod+mod)%mod)
#define all(a) a.begin(), a.end()
#define MP make_pair
#define lc id<<1
#define rc lc|1
#define mid (l+r)/2
#define kill(a) cout << a << "\n", exit(0)
typedef pair<int,int> pii;
typedef pair<long long ,long long> pll;
typedef long long ll;
typedef long double ld;
typedef vector<vector<ll>> matrix;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll const maxn=5e4+10, INF=1e9+10, LOG=22, sq=65;
ll poww(ll a, ll b, ll mod) {
if (b == 0) return 1;
return 1 * poww(1 * a * a % mod, b / 2, mod) * ((b % 2 == 1) ? a : 1) % mod;
}
int n, m, k, o, f[maxn], l[maxn], dis[maxn];
vector<pair<pii, int>> E;
map<pii, int> mp;
int solve(int a, int b)
{
if(a==b) return 0;
if(a>b || !f[a] || !l[b]) return -1;
if(mp[{a, b}]!=0) return mp[{a, b}];
fill(dis+a, dis+b+1, INF);
vector<int> s;
dis[a]=0;
for(int i=f[a];i<=min(m, l[b]);i++)
{
auto t=E[i-1];
int v=t.F.F, u=t.F.S, w=t.S;
if(dis[v]+w<dis[u]) dis[u]=dis[v]+w;
// s.pb(u);
}
// for(int i:s) mp[{a, i}]=dis[i];
mp[{a, b}]=dis[b];
return mp[{a, b}];
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>k>>n>>m>>o;
for(int i=1;i<=m;i++)
{
int v, u, w;
cin>>v>>u>>w;
E.pb({{v, u}, w});
}
fill(f, f+maxn, 0);
fill(l, l+maxn, 0);
int cur=1;
sort(all(E));
for(auto t:E)
{
int v=t.F.F, u=t.F.S;
if(f[v]==0) f[v]=cur;
l[u]=cur;
cur++;
}
while(o--)
{
int a, b;
cin>>a>>b;
int ans=solve(a, b);
if(ans<INF) cout<<ans<<"\n";
else cout<<-1<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
3196 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
2 ms |
848 KB |
Output is correct |
6 |
Correct |
2 ms |
848 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
284 ms |
3188 KB |
Output is correct |
9 |
Correct |
249 ms |
3008 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1236 ms |
4296 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
5 ms |
848 KB |
Output is correct |
8 |
Correct |
5 ms |
1104 KB |
Output is correct |
9 |
Correct |
339 ms |
3008 KB |
Output is correct |
10 |
Correct |
2731 ms |
6340 KB |
Output is correct |
11 |
Correct |
1740 ms |
4612 KB |
Output is correct |
12 |
Correct |
393 ms |
3772 KB |
Output is correct |
13 |
Correct |
911 ms |
6368 KB |
Output is correct |
14 |
Correct |
535 ms |
3524 KB |
Output is correct |
15 |
Correct |
462 ms |
3272 KB |
Output is correct |
16 |
Correct |
473 ms |
3272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
15 ms |
2504 KB |
Output is correct |
11 |
Correct |
36 ms |
3652 KB |
Output is correct |
12 |
Correct |
56 ms |
6340 KB |
Output is correct |
13 |
Correct |
63 ms |
6352 KB |
Output is correct |
14 |
Correct |
49 ms |
4264 KB |
Output is correct |
15 |
Correct |
33 ms |
3272 KB |
Output is correct |
16 |
Correct |
29 ms |
3272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
15 ms |
2504 KB |
Output is correct |
11 |
Correct |
36 ms |
3652 KB |
Output is correct |
12 |
Correct |
56 ms |
6340 KB |
Output is correct |
13 |
Correct |
63 ms |
6352 KB |
Output is correct |
14 |
Correct |
49 ms |
4264 KB |
Output is correct |
15 |
Correct |
33 ms |
3272 KB |
Output is correct |
16 |
Correct |
29 ms |
3272 KB |
Output is correct |
17 |
Correct |
371 ms |
3780 KB |
Output is correct |
18 |
Correct |
1 ms |
848 KB |
Output is correct |
19 |
Correct |
1 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
1 ms |
848 KB |
Output is correct |
22 |
Correct |
1 ms |
848 KB |
Output is correct |
23 |
Correct |
5 ms |
1104 KB |
Output is correct |
24 |
Correct |
6 ms |
1104 KB |
Output is correct |
25 |
Correct |
14 ms |
1104 KB |
Output is correct |
26 |
Correct |
9 ms |
1104 KB |
Output is correct |
27 |
Correct |
90 ms |
2504 KB |
Output is correct |
28 |
Correct |
648 ms |
6340 KB |
Output is correct |
29 |
Correct |
670 ms |
6336 KB |
Output is correct |
30 |
Correct |
411 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
3196 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
2 ms |
848 KB |
Output is correct |
6 |
Correct |
2 ms |
848 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
284 ms |
3188 KB |
Output is correct |
9 |
Correct |
249 ms |
3008 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
11 |
Correct |
1236 ms |
4296 KB |
Output is correct |
12 |
Correct |
1 ms |
848 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
848 KB |
Output is correct |
16 |
Correct |
1 ms |
848 KB |
Output is correct |
17 |
Correct |
5 ms |
848 KB |
Output is correct |
18 |
Correct |
5 ms |
1104 KB |
Output is correct |
19 |
Correct |
339 ms |
3008 KB |
Output is correct |
20 |
Correct |
2731 ms |
6340 KB |
Output is correct |
21 |
Correct |
1740 ms |
4612 KB |
Output is correct |
22 |
Correct |
393 ms |
3772 KB |
Output is correct |
23 |
Correct |
911 ms |
6368 KB |
Output is correct |
24 |
Correct |
535 ms |
3524 KB |
Output is correct |
25 |
Correct |
462 ms |
3272 KB |
Output is correct |
26 |
Correct |
473 ms |
3272 KB |
Output is correct |
27 |
Correct |
1 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
848 KB |
Output is correct |
30 |
Correct |
1 ms |
848 KB |
Output is correct |
31 |
Correct |
1 ms |
848 KB |
Output is correct |
32 |
Correct |
1 ms |
848 KB |
Output is correct |
33 |
Correct |
1 ms |
848 KB |
Output is correct |
34 |
Correct |
2 ms |
848 KB |
Output is correct |
35 |
Correct |
3 ms |
848 KB |
Output is correct |
36 |
Correct |
15 ms |
2504 KB |
Output is correct |
37 |
Correct |
36 ms |
3652 KB |
Output is correct |
38 |
Correct |
56 ms |
6340 KB |
Output is correct |
39 |
Correct |
63 ms |
6352 KB |
Output is correct |
40 |
Correct |
49 ms |
4264 KB |
Output is correct |
41 |
Correct |
33 ms |
3272 KB |
Output is correct |
42 |
Correct |
29 ms |
3272 KB |
Output is correct |
43 |
Correct |
371 ms |
3780 KB |
Output is correct |
44 |
Correct |
1 ms |
848 KB |
Output is correct |
45 |
Correct |
1 ms |
848 KB |
Output is correct |
46 |
Correct |
1 ms |
860 KB |
Output is correct |
47 |
Correct |
1 ms |
848 KB |
Output is correct |
48 |
Correct |
1 ms |
848 KB |
Output is correct |
49 |
Correct |
5 ms |
1104 KB |
Output is correct |
50 |
Correct |
6 ms |
1104 KB |
Output is correct |
51 |
Correct |
14 ms |
1104 KB |
Output is correct |
52 |
Correct |
9 ms |
1104 KB |
Output is correct |
53 |
Correct |
90 ms |
2504 KB |
Output is correct |
54 |
Correct |
648 ms |
6340 KB |
Output is correct |
55 |
Correct |
670 ms |
6336 KB |
Output is correct |
56 |
Correct |
411 ms |
4204 KB |
Output is correct |
57 |
Correct |
2847 ms |
7352 KB |
Output is correct |
58 |
Correct |
274 ms |
3008 KB |
Output is correct |
59 |
Correct |
1287 ms |
4600 KB |
Output is correct |