# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
696814 |
2023-02-07T10:28:48 Z |
vjudge1 |
Toll (BOI17_toll) |
C++17 |
|
1065 ms |
386380 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define gcd __gcd
#define endl '\n'
const int N=200050,M=1000000007;
const ll INF=1e18;
struct matrix{
ll n, m;
vector<vector<ll>> a;
matrix(ll x, ll y, ll v=0){
n=x, m=y;
a.assign(n, vector<ll>(m, v));
}
auto & operator [](ll i){return a[i];}
const auto & operator [](ll i)const{return a[i];}
matrix()=default;
friend ostream& operator <<(ostream& stream, const matrix &x){
for(auto i:x.a){
for(auto j:i) stream<<j<<" ";
stream<<endl;
}
return stream;
}
matrix operator *(const matrix b){
matrix a=*this, res(a.n, b.m, INF);
// cout<<b<<a;
for(ll i=0; i<a.n; i++)
for(ll j=0; j<b.m; j++)
for(ll k=0; k<a.m; k++)
res[i][j]=min(res[i][j], a[i][k]+b[k][j]);
// cout<<res<<"\n";
return res;
}
};
matrix p[N][17];
ll k, n, m, q, a, b, t;
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(nullptr); cout.tie(nullptr);
cin>>k>>n>>m>>q;
for(ll i=0; i<n; i++)
for(ll j=0; j<17; j++) p[i][j]=matrix(k, k, INF);
while(m--){
cin>>a>>b>>t;
p[a/k][0][a%k][b%k]=t;
}
for(ll i=1; (1<<i)<=n; i++)
for(ll j=0; j+(1<<i)-1<=n; j++){
p[j][i]=p[j][i-1]*p[j+(1<<(i-1))][i-1];
}
while(q--){
cin>>a>>b;
if(a == b){
cout<<0<<endl;
continue;
}
ll now=a/k, l=b/k-a/k;
matrix res(k, k, INF);
for(ll i=0; i<k; i++) res[i][i]=0;
for(ll i=0; i<17; i++)
if(l&(1<<i)){
res=res*p[now][i];
now+=(1<<i);
}
cout<<(res[a%k][b%k]==INF? -1: res[a%k][b%k])<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
186664 KB |
Output is correct |
2 |
Correct |
68 ms |
133392 KB |
Output is correct |
3 |
Correct |
69 ms |
133372 KB |
Output is correct |
4 |
Correct |
61 ms |
133372 KB |
Output is correct |
5 |
Correct |
66 ms |
134396 KB |
Output is correct |
6 |
Correct |
66 ms |
134400 KB |
Output is correct |
7 |
Correct |
69 ms |
134428 KB |
Output is correct |
8 |
Correct |
422 ms |
186664 KB |
Output is correct |
9 |
Correct |
401 ms |
186668 KB |
Output is correct |
10 |
Correct |
380 ms |
186668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
597 ms |
239868 KB |
Output is correct |
2 |
Correct |
63 ms |
133328 KB |
Output is correct |
3 |
Correct |
62 ms |
133416 KB |
Output is correct |
4 |
Correct |
63 ms |
133356 KB |
Output is correct |
5 |
Correct |
63 ms |
133348 KB |
Output is correct |
6 |
Correct |
62 ms |
133472 KB |
Output is correct |
7 |
Correct |
87 ms |
134504 KB |
Output is correct |
8 |
Correct |
84 ms |
135484 KB |
Output is correct |
9 |
Correct |
388 ms |
186556 KB |
Output is correct |
10 |
Correct |
791 ms |
279872 KB |
Output is correct |
11 |
Correct |
587 ms |
239980 KB |
Output is correct |
12 |
Correct |
807 ms |
279788 KB |
Output is correct |
13 |
Correct |
808 ms |
317176 KB |
Output is correct |
14 |
Correct |
501 ms |
221240 KB |
Output is correct |
15 |
Correct |
816 ms |
317048 KB |
Output is correct |
16 |
Correct |
770 ms |
317132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
133288 KB |
Output is correct |
2 |
Correct |
67 ms |
133312 KB |
Output is correct |
3 |
Correct |
63 ms |
133332 KB |
Output is correct |
4 |
Correct |
65 ms |
133340 KB |
Output is correct |
5 |
Correct |
63 ms |
133368 KB |
Output is correct |
6 |
Correct |
67 ms |
134388 KB |
Output is correct |
7 |
Correct |
69 ms |
135528 KB |
Output is correct |
8 |
Correct |
87 ms |
139448 KB |
Output is correct |
9 |
Correct |
89 ms |
138464 KB |
Output is correct |
10 |
Correct |
386 ms |
186648 KB |
Output is correct |
11 |
Correct |
577 ms |
239868 KB |
Output is correct |
12 |
Correct |
780 ms |
279796 KB |
Output is correct |
13 |
Correct |
764 ms |
279788 KB |
Output is correct |
14 |
Correct |
757 ms |
279784 KB |
Output is correct |
15 |
Correct |
745 ms |
317004 KB |
Output is correct |
16 |
Correct |
754 ms |
317040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
133288 KB |
Output is correct |
2 |
Correct |
67 ms |
133312 KB |
Output is correct |
3 |
Correct |
63 ms |
133332 KB |
Output is correct |
4 |
Correct |
65 ms |
133340 KB |
Output is correct |
5 |
Correct |
63 ms |
133368 KB |
Output is correct |
6 |
Correct |
67 ms |
134388 KB |
Output is correct |
7 |
Correct |
69 ms |
135528 KB |
Output is correct |
8 |
Correct |
87 ms |
139448 KB |
Output is correct |
9 |
Correct |
89 ms |
138464 KB |
Output is correct |
10 |
Correct |
386 ms |
186648 KB |
Output is correct |
11 |
Correct |
577 ms |
239868 KB |
Output is correct |
12 |
Correct |
780 ms |
279796 KB |
Output is correct |
13 |
Correct |
764 ms |
279788 KB |
Output is correct |
14 |
Correct |
757 ms |
279784 KB |
Output is correct |
15 |
Correct |
745 ms |
317004 KB |
Output is correct |
16 |
Correct |
754 ms |
317040 KB |
Output is correct |
17 |
Correct |
572 ms |
239924 KB |
Output is correct |
18 |
Correct |
63 ms |
133324 KB |
Output is correct |
19 |
Correct |
67 ms |
133436 KB |
Output is correct |
20 |
Correct |
64 ms |
133364 KB |
Output is correct |
21 |
Correct |
64 ms |
133360 KB |
Output is correct |
22 |
Correct |
62 ms |
133460 KB |
Output is correct |
23 |
Correct |
71 ms |
134476 KB |
Output is correct |
24 |
Correct |
76 ms |
135536 KB |
Output is correct |
25 |
Correct |
89 ms |
139440 KB |
Output is correct |
26 |
Correct |
84 ms |
138468 KB |
Output is correct |
27 |
Correct |
401 ms |
186616 KB |
Output is correct |
28 |
Correct |
784 ms |
279808 KB |
Output is correct |
29 |
Correct |
823 ms |
279784 KB |
Output is correct |
30 |
Correct |
776 ms |
279808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
426 ms |
186664 KB |
Output is correct |
2 |
Correct |
68 ms |
133392 KB |
Output is correct |
3 |
Correct |
69 ms |
133372 KB |
Output is correct |
4 |
Correct |
61 ms |
133372 KB |
Output is correct |
5 |
Correct |
66 ms |
134396 KB |
Output is correct |
6 |
Correct |
66 ms |
134400 KB |
Output is correct |
7 |
Correct |
69 ms |
134428 KB |
Output is correct |
8 |
Correct |
422 ms |
186664 KB |
Output is correct |
9 |
Correct |
401 ms |
186668 KB |
Output is correct |
10 |
Correct |
380 ms |
186668 KB |
Output is correct |
11 |
Correct |
597 ms |
239868 KB |
Output is correct |
12 |
Correct |
63 ms |
133328 KB |
Output is correct |
13 |
Correct |
62 ms |
133416 KB |
Output is correct |
14 |
Correct |
63 ms |
133356 KB |
Output is correct |
15 |
Correct |
63 ms |
133348 KB |
Output is correct |
16 |
Correct |
62 ms |
133472 KB |
Output is correct |
17 |
Correct |
87 ms |
134504 KB |
Output is correct |
18 |
Correct |
84 ms |
135484 KB |
Output is correct |
19 |
Correct |
388 ms |
186556 KB |
Output is correct |
20 |
Correct |
791 ms |
279872 KB |
Output is correct |
21 |
Correct |
587 ms |
239980 KB |
Output is correct |
22 |
Correct |
807 ms |
279788 KB |
Output is correct |
23 |
Correct |
808 ms |
317176 KB |
Output is correct |
24 |
Correct |
501 ms |
221240 KB |
Output is correct |
25 |
Correct |
816 ms |
317048 KB |
Output is correct |
26 |
Correct |
770 ms |
317132 KB |
Output is correct |
27 |
Correct |
62 ms |
133288 KB |
Output is correct |
28 |
Correct |
67 ms |
133312 KB |
Output is correct |
29 |
Correct |
63 ms |
133332 KB |
Output is correct |
30 |
Correct |
65 ms |
133340 KB |
Output is correct |
31 |
Correct |
63 ms |
133368 KB |
Output is correct |
32 |
Correct |
67 ms |
134388 KB |
Output is correct |
33 |
Correct |
69 ms |
135528 KB |
Output is correct |
34 |
Correct |
87 ms |
139448 KB |
Output is correct |
35 |
Correct |
89 ms |
138464 KB |
Output is correct |
36 |
Correct |
386 ms |
186648 KB |
Output is correct |
37 |
Correct |
577 ms |
239868 KB |
Output is correct |
38 |
Correct |
780 ms |
279796 KB |
Output is correct |
39 |
Correct |
764 ms |
279788 KB |
Output is correct |
40 |
Correct |
757 ms |
279784 KB |
Output is correct |
41 |
Correct |
745 ms |
317004 KB |
Output is correct |
42 |
Correct |
754 ms |
317040 KB |
Output is correct |
43 |
Correct |
572 ms |
239924 KB |
Output is correct |
44 |
Correct |
63 ms |
133324 KB |
Output is correct |
45 |
Correct |
67 ms |
133436 KB |
Output is correct |
46 |
Correct |
64 ms |
133364 KB |
Output is correct |
47 |
Correct |
64 ms |
133360 KB |
Output is correct |
48 |
Correct |
62 ms |
133460 KB |
Output is correct |
49 |
Correct |
71 ms |
134476 KB |
Output is correct |
50 |
Correct |
76 ms |
135536 KB |
Output is correct |
51 |
Correct |
89 ms |
139440 KB |
Output is correct |
52 |
Correct |
84 ms |
138468 KB |
Output is correct |
53 |
Correct |
401 ms |
186616 KB |
Output is correct |
54 |
Correct |
784 ms |
279808 KB |
Output is correct |
55 |
Correct |
823 ms |
279784 KB |
Output is correct |
56 |
Correct |
776 ms |
279808 KB |
Output is correct |
57 |
Correct |
1065 ms |
386380 KB |
Output is correct |
58 |
Correct |
407 ms |
186676 KB |
Output is correct |
59 |
Correct |
606 ms |
240064 KB |
Output is correct |