# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
760514 |
2023-06-17T17:04:43 Z |
shadow_sami |
Toll (BOI17_toll) |
C++17 |
|
351 ms |
101184 KB |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pi;
#define ff first
#define ss second
#define fip(a,b) for(ll i = a ; i < b ; i++)
#define fjp(a,b) for(ll j = a ; j < b ; j++)
#define fp(x,a,b) for(ll x = a ; x < b ; x++)
#define fin(a,b) for(ll i = a : i >= b; i--)
#define fjn(a,b) for(ll j = a : j >= b; j--)
#define fn(x,a,b) for(ll x = a ; x >= b ; x--);
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define total_one(a) __builtin_popcount(a)
#define front_zero(a) __builtin_clzll(a)
#define back_zero(a) __builtin_ctzll(a)
#define fx(a) for(auto x : a)
#define nli "\n"
void _printn(ll a){ cerr<<a<<" ";}
void _printn(int a){ cerr<<a<<" ";}
template <class T,class V> void _printn(pair<T,V> a){ cerr<<"( "<<a.ff<<" , "<<a.ss<<" )";}
template <class T> void _printn(vector<T> a){
cerr<<"[ ";
for(auto x : a){
_printn(x);
cerr<< " ";
}
cerr<<"] ";
return;
}
#ifndef ONLINE_JUDGE
#define debug(x) cerr<< #x <<" ";_printn(x); cerr << nli;
#else
#define debug(x)
#endif
const ll mx = 1e5+5;
ll n,m,k,q,tp,tp2,res,sum,tptp,cnt,ans;
bool f = false;
ll sr,de;
vector<pi> adj[mx][20];
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input1.txt","r",stdin);
// freopen("output1.txt","w",stdout);
// freopen("error1.txt","w",stderr);
// #endif
cin>>k>>n>>m>>tptp;
vector<pi> ve;
fip(0,m){
cin>>sr>>de>>tp;
adj[sr][0].push_back({de,tp});
}
fjp(1,20){
fip(0,n){
sr = i;
if(i/k + (1<<j) > (n-1)/k)
break;
ve.clear();
fx(adj[sr][j-1]){
for(auto y : adj[x.ff][j-1]){
ve.push_back({y.ff,x.ss+y.ss});
}
}
sort(ve.begin(),ve.end());
fip(0,(int)ve.size()){
if(i == 0 || ve[i].ff != ve[i-1].ff)
adj[sr][j].push_back({ve[i].ff,ve[i].ss});
}
}
}
ll l,r;
vector<pi> v,v2;
while(tptp--){
cin>>sr>>de;
if(sr==de){
cout<<0<<nli;
continue;
}
v.clear();
l = sr;
r = de;
ans = 1e18;
v2.clear();
v.push_back({l,0});
while(1){
if(l/k - r/k >= 0)
break;
res = (r/k) - (l/k);
res = 63 - front_zero(res);
v2.clear();
fx(v){
for( auto y : adj[x.ff][res]){
v2.push_back({y.ff,x.ss+y.ss});
}
}
if((int)v2.size()==0)
break;
v.clear();
sort(v2.begin(),v2.end());
fip(0,(int)v2.size()){
if(i==0 || v2[i].ff != v2[i-1].ff)
v.push_back(v2[i]);
}
l = v[0].ff;
}
fx(v)
if(x.ff == de)
ans = min(ans,x.ss);
if(ans>1e17)
ans = -1;
cout<<ans<<nli;
}
cerr << "time elapsed : " <<setprecision(6)<< clock() * 1000.00 / CLOCKS_PER_SEC << " ms"<<nli;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
70336 KB |
Output is correct |
2 |
Correct |
24 ms |
47188 KB |
Output is correct |
3 |
Correct |
23 ms |
47236 KB |
Output is correct |
4 |
Correct |
23 ms |
47288 KB |
Output is correct |
5 |
Correct |
25 ms |
47348 KB |
Output is correct |
6 |
Correct |
25 ms |
47312 KB |
Output is correct |
7 |
Correct |
25 ms |
47376 KB |
Output is correct |
8 |
Correct |
73 ms |
62140 KB |
Output is correct |
9 |
Correct |
62 ms |
53528 KB |
Output is correct |
10 |
Correct |
36 ms |
47316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
76976 KB |
Output is correct |
2 |
Correct |
24 ms |
47188 KB |
Output is correct |
3 |
Correct |
25 ms |
47220 KB |
Output is correct |
4 |
Correct |
24 ms |
47288 KB |
Output is correct |
5 |
Correct |
24 ms |
47260 KB |
Output is correct |
6 |
Correct |
25 ms |
47288 KB |
Output is correct |
7 |
Correct |
27 ms |
47560 KB |
Output is correct |
8 |
Correct |
31 ms |
47808 KB |
Output is correct |
9 |
Correct |
72 ms |
62988 KB |
Output is correct |
10 |
Correct |
238 ms |
100248 KB |
Output is correct |
11 |
Correct |
171 ms |
81380 KB |
Output is correct |
12 |
Correct |
90 ms |
61024 KB |
Output is correct |
13 |
Correct |
303 ms |
99316 KB |
Output is correct |
14 |
Correct |
136 ms |
78028 KB |
Output is correct |
15 |
Correct |
236 ms |
89432 KB |
Output is correct |
16 |
Correct |
246 ms |
89140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
47264 KB |
Output is correct |
2 |
Correct |
24 ms |
47188 KB |
Output is correct |
3 |
Correct |
25 ms |
47292 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
25 ms |
47236 KB |
Output is correct |
6 |
Correct |
29 ms |
47400 KB |
Output is correct |
7 |
Correct |
26 ms |
47580 KB |
Output is correct |
8 |
Correct |
30 ms |
48264 KB |
Output is correct |
9 |
Correct |
28 ms |
47828 KB |
Output is correct |
10 |
Correct |
73 ms |
63204 KB |
Output is correct |
11 |
Correct |
149 ms |
80820 KB |
Output is correct |
12 |
Correct |
221 ms |
100000 KB |
Output is correct |
13 |
Correct |
227 ms |
101028 KB |
Output is correct |
14 |
Correct |
198 ms |
97044 KB |
Output is correct |
15 |
Correct |
226 ms |
89296 KB |
Output is correct |
16 |
Correct |
263 ms |
89100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
47264 KB |
Output is correct |
2 |
Correct |
24 ms |
47188 KB |
Output is correct |
3 |
Correct |
25 ms |
47292 KB |
Output is correct |
4 |
Correct |
23 ms |
47188 KB |
Output is correct |
5 |
Correct |
25 ms |
47236 KB |
Output is correct |
6 |
Correct |
29 ms |
47400 KB |
Output is correct |
7 |
Correct |
26 ms |
47580 KB |
Output is correct |
8 |
Correct |
30 ms |
48264 KB |
Output is correct |
9 |
Correct |
28 ms |
47828 KB |
Output is correct |
10 |
Correct |
73 ms |
63204 KB |
Output is correct |
11 |
Correct |
149 ms |
80820 KB |
Output is correct |
12 |
Correct |
221 ms |
100000 KB |
Output is correct |
13 |
Correct |
227 ms |
101028 KB |
Output is correct |
14 |
Correct |
198 ms |
97044 KB |
Output is correct |
15 |
Correct |
226 ms |
89296 KB |
Output is correct |
16 |
Correct |
263 ms |
89100 KB |
Output is correct |
17 |
Correct |
156 ms |
80924 KB |
Output is correct |
18 |
Correct |
24 ms |
47172 KB |
Output is correct |
19 |
Correct |
25 ms |
47188 KB |
Output is correct |
20 |
Correct |
29 ms |
47260 KB |
Output is correct |
21 |
Correct |
25 ms |
47188 KB |
Output is correct |
22 |
Correct |
24 ms |
47268 KB |
Output is correct |
23 |
Correct |
25 ms |
47436 KB |
Output is correct |
24 |
Correct |
26 ms |
47680 KB |
Output is correct |
25 |
Correct |
34 ms |
48196 KB |
Output is correct |
26 |
Correct |
31 ms |
47860 KB |
Output is correct |
27 |
Correct |
72 ms |
62848 KB |
Output is correct |
28 |
Correct |
266 ms |
100172 KB |
Output is correct |
29 |
Correct |
257 ms |
101184 KB |
Output is correct |
30 |
Correct |
226 ms |
93500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
70336 KB |
Output is correct |
2 |
Correct |
24 ms |
47188 KB |
Output is correct |
3 |
Correct |
23 ms |
47236 KB |
Output is correct |
4 |
Correct |
23 ms |
47288 KB |
Output is correct |
5 |
Correct |
25 ms |
47348 KB |
Output is correct |
6 |
Correct |
25 ms |
47312 KB |
Output is correct |
7 |
Correct |
25 ms |
47376 KB |
Output is correct |
8 |
Correct |
73 ms |
62140 KB |
Output is correct |
9 |
Correct |
62 ms |
53528 KB |
Output is correct |
10 |
Correct |
36 ms |
47316 KB |
Output is correct |
11 |
Correct |
147 ms |
76976 KB |
Output is correct |
12 |
Correct |
24 ms |
47188 KB |
Output is correct |
13 |
Correct |
25 ms |
47220 KB |
Output is correct |
14 |
Correct |
24 ms |
47288 KB |
Output is correct |
15 |
Correct |
24 ms |
47260 KB |
Output is correct |
16 |
Correct |
25 ms |
47288 KB |
Output is correct |
17 |
Correct |
27 ms |
47560 KB |
Output is correct |
18 |
Correct |
31 ms |
47808 KB |
Output is correct |
19 |
Correct |
72 ms |
62988 KB |
Output is correct |
20 |
Correct |
238 ms |
100248 KB |
Output is correct |
21 |
Correct |
171 ms |
81380 KB |
Output is correct |
22 |
Correct |
90 ms |
61024 KB |
Output is correct |
23 |
Correct |
303 ms |
99316 KB |
Output is correct |
24 |
Correct |
136 ms |
78028 KB |
Output is correct |
25 |
Correct |
236 ms |
89432 KB |
Output is correct |
26 |
Correct |
246 ms |
89140 KB |
Output is correct |
27 |
Correct |
25 ms |
47264 KB |
Output is correct |
28 |
Correct |
24 ms |
47188 KB |
Output is correct |
29 |
Correct |
25 ms |
47292 KB |
Output is correct |
30 |
Correct |
23 ms |
47188 KB |
Output is correct |
31 |
Correct |
25 ms |
47236 KB |
Output is correct |
32 |
Correct |
29 ms |
47400 KB |
Output is correct |
33 |
Correct |
26 ms |
47580 KB |
Output is correct |
34 |
Correct |
30 ms |
48264 KB |
Output is correct |
35 |
Correct |
28 ms |
47828 KB |
Output is correct |
36 |
Correct |
73 ms |
63204 KB |
Output is correct |
37 |
Correct |
149 ms |
80820 KB |
Output is correct |
38 |
Correct |
221 ms |
100000 KB |
Output is correct |
39 |
Correct |
227 ms |
101028 KB |
Output is correct |
40 |
Correct |
198 ms |
97044 KB |
Output is correct |
41 |
Correct |
226 ms |
89296 KB |
Output is correct |
42 |
Correct |
263 ms |
89100 KB |
Output is correct |
43 |
Correct |
156 ms |
80924 KB |
Output is correct |
44 |
Correct |
24 ms |
47172 KB |
Output is correct |
45 |
Correct |
25 ms |
47188 KB |
Output is correct |
46 |
Correct |
29 ms |
47260 KB |
Output is correct |
47 |
Correct |
25 ms |
47188 KB |
Output is correct |
48 |
Correct |
24 ms |
47268 KB |
Output is correct |
49 |
Correct |
25 ms |
47436 KB |
Output is correct |
50 |
Correct |
26 ms |
47680 KB |
Output is correct |
51 |
Correct |
34 ms |
48196 KB |
Output is correct |
52 |
Correct |
31 ms |
47860 KB |
Output is correct |
53 |
Correct |
72 ms |
62848 KB |
Output is correct |
54 |
Correct |
266 ms |
100172 KB |
Output is correct |
55 |
Correct |
257 ms |
101184 KB |
Output is correct |
56 |
Correct |
226 ms |
93500 KB |
Output is correct |
57 |
Correct |
351 ms |
100584 KB |
Output is correct |
58 |
Correct |
72 ms |
62912 KB |
Output is correct |
59 |
Correct |
159 ms |
81468 KB |
Output is correct |