# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
896354 |
2024-01-01T09:57:53 Z |
pcc |
Toll (BOI17_toll) |
C++14 |
|
133 ms |
248612 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxc = 5;
const int mxn = 5e5+10;
const int inf = 1e9+10;
struct mat{
int val[mxc][mxc];
mat(){
for(auto &i:val)for(auto &j:i)j = inf;
}
int* operator[](int k){
return (int*)val[k];
}
mat operator*(mat b)const{
mat re = mat();
for(int i = 0;i<mxc;i++)for(int j = 0;j<mxc;j++)for(int k = 0;k<mxc;k++){
re[j][k] = min(re[j][k],val[j][i]+b[i][k]);
}
return re;
}
};
int N,K,Q,M,blk;
mat segtree[mxn*4];
mat paths[mxn];
void build(int now,int l,int r){
if(l == r){
segtree[now] = paths[l];
return;
}
int mid = (l+r)>>1;
build(now*2+1,l,mid);
build(now*2+2,mid+1,r);
segtree[now] = segtree[now*2+1]*segtree[now*2+2];
return;
}
mat getval(int now,int l,int r,int s,int e){
if(l>=s&&e>=r)return segtree[now];
int mid = (l+r)>>1;
if(mid>=e)return getval(now*2+1,l,mid,s,e);
else if(mid<s)return getval(now*2+2,mid+1,r,s,e);
else return getval(now*2+1,l,mid,s,e)*getval(now*2+2,mid+1,r,s,e);
}
main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>K>>N>>M>>Q;
int blk = (N+K-1)/K;
for(int i = 0;i<M;i++){
int a,b,c;
cin>>a>>b>>c;
paths[a/K][a%K][b%K] = min(paths[a/K][a%K][b%K],c);
}
build(0,0,blk);
while(Q--){
int a,b;
cin>>a>>b;
if(a/K>=b/K){
cout<<"-1\n";
continue;
}
auto re = getval(0,0,blk,a/K,b/K-1);
if(re[a%K][b%K]>=inf)cout<<"-1\n";
else cout<<re[a%K][b%K]<<'\n';
}
return 0;
}
Compilation message
toll.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
56 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
245092 KB |
Output is correct |
2 |
Correct |
69 ms |
244892 KB |
Output is correct |
3 |
Correct |
58 ms |
244816 KB |
Output is correct |
4 |
Correct |
51 ms |
244972 KB |
Output is correct |
5 |
Correct |
52 ms |
244964 KB |
Output is correct |
6 |
Correct |
54 ms |
245068 KB |
Output is correct |
7 |
Correct |
53 ms |
244888 KB |
Output is correct |
8 |
Correct |
92 ms |
246008 KB |
Output is correct |
9 |
Correct |
96 ms |
245940 KB |
Output is correct |
10 |
Correct |
78 ms |
245192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
245056 KB |
Output is correct |
2 |
Correct |
51 ms |
244840 KB |
Output is correct |
3 |
Correct |
67 ms |
244848 KB |
Output is correct |
4 |
Correct |
51 ms |
244912 KB |
Output is correct |
5 |
Correct |
51 ms |
244816 KB |
Output is correct |
6 |
Correct |
54 ms |
245036 KB |
Output is correct |
7 |
Correct |
59 ms |
245072 KB |
Output is correct |
8 |
Correct |
63 ms |
245088 KB |
Output is correct |
9 |
Correct |
98 ms |
245972 KB |
Output is correct |
10 |
Correct |
133 ms |
247380 KB |
Output is correct |
11 |
Correct |
86 ms |
246636 KB |
Output is correct |
12 |
Correct |
79 ms |
246148 KB |
Output is correct |
13 |
Correct |
91 ms |
247312 KB |
Output is correct |
14 |
Correct |
72 ms |
246352 KB |
Output is correct |
15 |
Correct |
68 ms |
246104 KB |
Output is correct |
16 |
Correct |
91 ms |
246268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
244816 KB |
Output is correct |
2 |
Correct |
59 ms |
244816 KB |
Output is correct |
3 |
Correct |
52 ms |
245060 KB |
Output is correct |
4 |
Correct |
51 ms |
244820 KB |
Output is correct |
5 |
Correct |
77 ms |
245076 KB |
Output is correct |
6 |
Correct |
54 ms |
245072 KB |
Output is correct |
7 |
Correct |
67 ms |
245032 KB |
Output is correct |
8 |
Correct |
53 ms |
245036 KB |
Output is correct |
9 |
Correct |
51 ms |
245084 KB |
Output is correct |
10 |
Correct |
74 ms |
245628 KB |
Output is correct |
11 |
Correct |
79 ms |
246584 KB |
Output is correct |
12 |
Correct |
93 ms |
247120 KB |
Output is correct |
13 |
Correct |
82 ms |
247360 KB |
Output is correct |
14 |
Correct |
93 ms |
246764 KB |
Output is correct |
15 |
Correct |
74 ms |
246100 KB |
Output is correct |
16 |
Correct |
67 ms |
246200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
244816 KB |
Output is correct |
2 |
Correct |
59 ms |
244816 KB |
Output is correct |
3 |
Correct |
52 ms |
245060 KB |
Output is correct |
4 |
Correct |
51 ms |
244820 KB |
Output is correct |
5 |
Correct |
77 ms |
245076 KB |
Output is correct |
6 |
Correct |
54 ms |
245072 KB |
Output is correct |
7 |
Correct |
67 ms |
245032 KB |
Output is correct |
8 |
Correct |
53 ms |
245036 KB |
Output is correct |
9 |
Correct |
51 ms |
245084 KB |
Output is correct |
10 |
Correct |
74 ms |
245628 KB |
Output is correct |
11 |
Correct |
79 ms |
246584 KB |
Output is correct |
12 |
Correct |
93 ms |
247120 KB |
Output is correct |
13 |
Correct |
82 ms |
247360 KB |
Output is correct |
14 |
Correct |
93 ms |
246764 KB |
Output is correct |
15 |
Correct |
74 ms |
246100 KB |
Output is correct |
16 |
Correct |
67 ms |
246200 KB |
Output is correct |
17 |
Correct |
122 ms |
246584 KB |
Output is correct |
18 |
Correct |
53 ms |
244932 KB |
Output is correct |
19 |
Correct |
51 ms |
244996 KB |
Output is correct |
20 |
Correct |
51 ms |
244964 KB |
Output is correct |
21 |
Correct |
52 ms |
244816 KB |
Output is correct |
22 |
Correct |
74 ms |
244820 KB |
Output is correct |
23 |
Correct |
65 ms |
244960 KB |
Output is correct |
24 |
Correct |
55 ms |
245076 KB |
Output is correct |
25 |
Correct |
66 ms |
244972 KB |
Output is correct |
26 |
Correct |
54 ms |
245140 KB |
Output is correct |
27 |
Correct |
77 ms |
245836 KB |
Output is correct |
28 |
Correct |
88 ms |
247220 KB |
Output is correct |
29 |
Correct |
89 ms |
247484 KB |
Output is correct |
30 |
Correct |
80 ms |
246864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
245092 KB |
Output is correct |
2 |
Correct |
69 ms |
244892 KB |
Output is correct |
3 |
Correct |
58 ms |
244816 KB |
Output is correct |
4 |
Correct |
51 ms |
244972 KB |
Output is correct |
5 |
Correct |
52 ms |
244964 KB |
Output is correct |
6 |
Correct |
54 ms |
245068 KB |
Output is correct |
7 |
Correct |
53 ms |
244888 KB |
Output is correct |
8 |
Correct |
92 ms |
246008 KB |
Output is correct |
9 |
Correct |
96 ms |
245940 KB |
Output is correct |
10 |
Correct |
78 ms |
245192 KB |
Output is correct |
11 |
Correct |
86 ms |
245056 KB |
Output is correct |
12 |
Correct |
51 ms |
244840 KB |
Output is correct |
13 |
Correct |
67 ms |
244848 KB |
Output is correct |
14 |
Correct |
51 ms |
244912 KB |
Output is correct |
15 |
Correct |
51 ms |
244816 KB |
Output is correct |
16 |
Correct |
54 ms |
245036 KB |
Output is correct |
17 |
Correct |
59 ms |
245072 KB |
Output is correct |
18 |
Correct |
63 ms |
245088 KB |
Output is correct |
19 |
Correct |
98 ms |
245972 KB |
Output is correct |
20 |
Correct |
133 ms |
247380 KB |
Output is correct |
21 |
Correct |
86 ms |
246636 KB |
Output is correct |
22 |
Correct |
79 ms |
246148 KB |
Output is correct |
23 |
Correct |
91 ms |
247312 KB |
Output is correct |
24 |
Correct |
72 ms |
246352 KB |
Output is correct |
25 |
Correct |
68 ms |
246104 KB |
Output is correct |
26 |
Correct |
91 ms |
246268 KB |
Output is correct |
27 |
Correct |
55 ms |
244816 KB |
Output is correct |
28 |
Correct |
59 ms |
244816 KB |
Output is correct |
29 |
Correct |
52 ms |
245060 KB |
Output is correct |
30 |
Correct |
51 ms |
244820 KB |
Output is correct |
31 |
Correct |
77 ms |
245076 KB |
Output is correct |
32 |
Correct |
54 ms |
245072 KB |
Output is correct |
33 |
Correct |
67 ms |
245032 KB |
Output is correct |
34 |
Correct |
53 ms |
245036 KB |
Output is correct |
35 |
Correct |
51 ms |
245084 KB |
Output is correct |
36 |
Correct |
74 ms |
245628 KB |
Output is correct |
37 |
Correct |
79 ms |
246584 KB |
Output is correct |
38 |
Correct |
93 ms |
247120 KB |
Output is correct |
39 |
Correct |
82 ms |
247360 KB |
Output is correct |
40 |
Correct |
93 ms |
246764 KB |
Output is correct |
41 |
Correct |
74 ms |
246100 KB |
Output is correct |
42 |
Correct |
67 ms |
246200 KB |
Output is correct |
43 |
Correct |
122 ms |
246584 KB |
Output is correct |
44 |
Correct |
53 ms |
244932 KB |
Output is correct |
45 |
Correct |
51 ms |
244996 KB |
Output is correct |
46 |
Correct |
51 ms |
244964 KB |
Output is correct |
47 |
Correct |
52 ms |
244816 KB |
Output is correct |
48 |
Correct |
74 ms |
244820 KB |
Output is correct |
49 |
Correct |
65 ms |
244960 KB |
Output is correct |
50 |
Correct |
55 ms |
245076 KB |
Output is correct |
51 |
Correct |
66 ms |
244972 KB |
Output is correct |
52 |
Correct |
54 ms |
245140 KB |
Output is correct |
53 |
Correct |
77 ms |
245836 KB |
Output is correct |
54 |
Correct |
88 ms |
247220 KB |
Output is correct |
55 |
Correct |
89 ms |
247484 KB |
Output is correct |
56 |
Correct |
80 ms |
246864 KB |
Output is correct |
57 |
Correct |
124 ms |
248612 KB |
Output is correct |
58 |
Correct |
109 ms |
245892 KB |
Output is correct |
59 |
Correct |
97 ms |
246816 KB |
Output is correct |