# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
169949 |
2019-12-23T11:03:37 Z |
moonrabbit2 |
Toll (BOI17_toll) |
C++17 |
|
165 ms |
12284 KB |
#include <bits/stdc++.h>
#define x first
#define y second
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef tuple<int,int,int> tii;
typedef tuple<ll,ll,ll> tll;
typedef vector<vector<ll>> mat;
const ll mod=1e9+7;
const int N=5e4+5;
int n,m,q,k;
vector<tii> edge[N];
struct node{
int d[5][5]={0};
};
node tree[4*N];
void init(int nd,int l,int r){
if(l==r){
for(int i=0;i<k;i++){
for(int j=0;j<k;j++){
if(i!=j) tree[nd].d[i][j]=1e9;
}
}
return;
}
int m=(l+r)>>1;
init(nd<<1,l,m); init(nd<<1|1,m+1,r);
for(int i=0;i<k;i++) for(int j=0;j<k;j++){
tree[nd].d[i][j]=1e9;
}
for(auto &it : edge[m]){
int u=get<0>(it)%k,v=get<1>(it)%k,c=get<2>(it);
for(int i=0;i<k;i++) for(int j=0;j<k;j++){
tree[nd].d[i][j]=min(tree[nd].d[i][j],tree[nd<<1].d[i][u]+c+tree[nd<<1|1].d[v][j]);
}
}
}
node qry(int nd,int l,int r,int s,int e){
node res;
if(s<=l&&r<=e) return tree[nd];
int m=(l+r)>>1;
if(e<=m) return qry(nd<<1,l,m,s,e);
if(m<s) return qry(nd<<1|1,m+1,r,s,e);
node n1=qry(nd<<1,l,m,s,e),n2=qry(nd<<1|1,m+1,r,s,e);
for(int i=0;i<k;i++) for(int j=0;j<k;j++){
res.d[i][j]=1e9;
}
for(auto &it : edge[m]){
int u=get<0>(it)%k,v=get<1>(it)%k,c=get<2>(it);
for(int i=0;i<k;i++) for(int j=0;j<k;j++){
res.d[i][j]=min(res.d[i][j],n1.d[i][u]+c+n2.d[v][j]);
}
}
return res;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>k>>n>>m>>q;
for(int u,v,c,i=1;i<=m;i++){
cin>>u>>v>>c;
edge[u/k].emplace_back(u,v,c);
}
init(1,0,(n-1)/k);
for(int u,v,i=1;i<=q;i++){
cin>>u>>v;
if(u/k>=v/k){
cout<<"-1\n";
continue;
}
node res=qry(1,0,(n-1)/k,u/k,v/k);
if(res.d[u%k][v%k]==1e9) cout<<"-1\n";
else cout<<res.d[u%k][v%k]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
10488 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
4 ms |
1656 KB |
Output is correct |
6 |
Correct |
4 ms |
1656 KB |
Output is correct |
7 |
Correct |
4 ms |
1656 KB |
Output is correct |
8 |
Correct |
66 ms |
10488 KB |
Output is correct |
9 |
Correct |
53 ms |
10360 KB |
Output is correct |
10 |
Correct |
26 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
11296 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1552 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1528 KB |
Output is correct |
6 |
Correct |
3 ms |
1528 KB |
Output is correct |
7 |
Correct |
9 ms |
1784 KB |
Output is correct |
8 |
Correct |
11 ms |
1784 KB |
Output is correct |
9 |
Correct |
45 ms |
10488 KB |
Output is correct |
10 |
Correct |
99 ms |
11128 KB |
Output is correct |
11 |
Correct |
71 ms |
11512 KB |
Output is correct |
12 |
Correct |
58 ms |
8824 KB |
Output is correct |
13 |
Correct |
90 ms |
8184 KB |
Output is correct |
14 |
Correct |
60 ms |
8544 KB |
Output is correct |
15 |
Correct |
50 ms |
5752 KB |
Output is correct |
16 |
Correct |
51 ms |
5880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1532 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1528 KB |
Output is correct |
6 |
Correct |
4 ms |
1656 KB |
Output is correct |
7 |
Correct |
4 ms |
1656 KB |
Output is correct |
8 |
Correct |
5 ms |
1656 KB |
Output is correct |
9 |
Correct |
4 ms |
1656 KB |
Output is correct |
10 |
Correct |
35 ms |
10360 KB |
Output is correct |
11 |
Correct |
52 ms |
11256 KB |
Output is correct |
12 |
Correct |
69 ms |
10976 KB |
Output is correct |
13 |
Correct |
79 ms |
12156 KB |
Output is correct |
14 |
Correct |
58 ms |
9848 KB |
Output is correct |
15 |
Correct |
39 ms |
5724 KB |
Output is correct |
16 |
Correct |
39 ms |
5752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1532 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1528 KB |
Output is correct |
6 |
Correct |
4 ms |
1656 KB |
Output is correct |
7 |
Correct |
4 ms |
1656 KB |
Output is correct |
8 |
Correct |
5 ms |
1656 KB |
Output is correct |
9 |
Correct |
4 ms |
1656 KB |
Output is correct |
10 |
Correct |
35 ms |
10360 KB |
Output is correct |
11 |
Correct |
52 ms |
11256 KB |
Output is correct |
12 |
Correct |
69 ms |
10976 KB |
Output is correct |
13 |
Correct |
79 ms |
12156 KB |
Output is correct |
14 |
Correct |
58 ms |
9848 KB |
Output is correct |
15 |
Correct |
39 ms |
5724 KB |
Output is correct |
16 |
Correct |
39 ms |
5752 KB |
Output is correct |
17 |
Correct |
60 ms |
11184 KB |
Output is correct |
18 |
Correct |
3 ms |
1528 KB |
Output is correct |
19 |
Correct |
3 ms |
1528 KB |
Output is correct |
20 |
Correct |
3 ms |
1528 KB |
Output is correct |
21 |
Correct |
3 ms |
1528 KB |
Output is correct |
22 |
Correct |
4 ms |
1528 KB |
Output is correct |
23 |
Correct |
7 ms |
1784 KB |
Output is correct |
24 |
Correct |
8 ms |
1784 KB |
Output is correct |
25 |
Correct |
18 ms |
1784 KB |
Output is correct |
26 |
Correct |
15 ms |
1784 KB |
Output is correct |
27 |
Correct |
39 ms |
10360 KB |
Output is correct |
28 |
Correct |
83 ms |
11068 KB |
Output is correct |
29 |
Correct |
91 ms |
12284 KB |
Output is correct |
30 |
Correct |
70 ms |
9976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
10488 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
4 ms |
1656 KB |
Output is correct |
6 |
Correct |
4 ms |
1656 KB |
Output is correct |
7 |
Correct |
4 ms |
1656 KB |
Output is correct |
8 |
Correct |
66 ms |
10488 KB |
Output is correct |
9 |
Correct |
53 ms |
10360 KB |
Output is correct |
10 |
Correct |
26 ms |
8184 KB |
Output is correct |
11 |
Correct |
70 ms |
11296 KB |
Output is correct |
12 |
Correct |
3 ms |
1528 KB |
Output is correct |
13 |
Correct |
3 ms |
1552 KB |
Output is correct |
14 |
Correct |
3 ms |
1528 KB |
Output is correct |
15 |
Correct |
3 ms |
1528 KB |
Output is correct |
16 |
Correct |
3 ms |
1528 KB |
Output is correct |
17 |
Correct |
9 ms |
1784 KB |
Output is correct |
18 |
Correct |
11 ms |
1784 KB |
Output is correct |
19 |
Correct |
45 ms |
10488 KB |
Output is correct |
20 |
Correct |
99 ms |
11128 KB |
Output is correct |
21 |
Correct |
71 ms |
11512 KB |
Output is correct |
22 |
Correct |
58 ms |
8824 KB |
Output is correct |
23 |
Correct |
90 ms |
8184 KB |
Output is correct |
24 |
Correct |
60 ms |
8544 KB |
Output is correct |
25 |
Correct |
50 ms |
5752 KB |
Output is correct |
26 |
Correct |
51 ms |
5880 KB |
Output is correct |
27 |
Correct |
3 ms |
1528 KB |
Output is correct |
28 |
Correct |
3 ms |
1528 KB |
Output is correct |
29 |
Correct |
3 ms |
1532 KB |
Output is correct |
30 |
Correct |
3 ms |
1528 KB |
Output is correct |
31 |
Correct |
3 ms |
1528 KB |
Output is correct |
32 |
Correct |
4 ms |
1656 KB |
Output is correct |
33 |
Correct |
4 ms |
1656 KB |
Output is correct |
34 |
Correct |
5 ms |
1656 KB |
Output is correct |
35 |
Correct |
4 ms |
1656 KB |
Output is correct |
36 |
Correct |
35 ms |
10360 KB |
Output is correct |
37 |
Correct |
52 ms |
11256 KB |
Output is correct |
38 |
Correct |
69 ms |
10976 KB |
Output is correct |
39 |
Correct |
79 ms |
12156 KB |
Output is correct |
40 |
Correct |
58 ms |
9848 KB |
Output is correct |
41 |
Correct |
39 ms |
5724 KB |
Output is correct |
42 |
Correct |
39 ms |
5752 KB |
Output is correct |
43 |
Correct |
60 ms |
11184 KB |
Output is correct |
44 |
Correct |
3 ms |
1528 KB |
Output is correct |
45 |
Correct |
3 ms |
1528 KB |
Output is correct |
46 |
Correct |
3 ms |
1528 KB |
Output is correct |
47 |
Correct |
3 ms |
1528 KB |
Output is correct |
48 |
Correct |
4 ms |
1528 KB |
Output is correct |
49 |
Correct |
7 ms |
1784 KB |
Output is correct |
50 |
Correct |
8 ms |
1784 KB |
Output is correct |
51 |
Correct |
18 ms |
1784 KB |
Output is correct |
52 |
Correct |
15 ms |
1784 KB |
Output is correct |
53 |
Correct |
39 ms |
10360 KB |
Output is correct |
54 |
Correct |
83 ms |
11068 KB |
Output is correct |
55 |
Correct |
91 ms |
12284 KB |
Output is correct |
56 |
Correct |
70 ms |
9976 KB |
Output is correct |
57 |
Correct |
165 ms |
11240 KB |
Output is correct |
58 |
Correct |
53 ms |
10524 KB |
Output is correct |
59 |
Correct |
81 ms |
11384 KB |
Output is correct |