# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087328 |
2024-09-12T13:36:40 Z |
LeonidCuk |
Toll (BOI17_toll) |
C++17 |
|
142 ms |
8532 KB |
#include <bits/stdc++.h>
using namespace std;
int n,k,q;
vector<pair<int,int>>g[50000],que;
vector<int>ans,pom[5];
void daq(int l,int r,vector<int>v)
{
if(l/k==r/k||l>r)
{
return;
}
int m=((l+r)/2)/k;
for(int i=m*k+1;i<=r;i++)
{
for(int j=0;j<k;j++)
{
pom[j][i]=INT_MAX;
}
}
for(int i=min(m*k,l);i<=r;i++)
{
if(i/k==m)
{
for(int j=0;j<k;j++)
{
if(j==i-m*k)
{
pom[j][i]=0;
}
else
{
pom[j][i]=INT_MAX;
}
}
}
for(auto p:g[i])
{
if(p.first>r)continue;
for(int j=0;j<k;j++)
{
if(pom[j][i]!=INT_MAX)
{
pom[j][p.first]=min(pom[j][i]+p.second,pom[j][p.first]);
}
}
}
}
for(int i=m*k-1;i>=l;i--)
{
for(int j=0;j<k;j++)
{
pom[j][i]=INT_MAX;
}
for(auto p:g[i])
{
for(int j=0;j<k;j++)
{
if(pom[j][p.first]!=INT_MAX)
{
pom[j][i]=min(pom[j][i],pom[j][p.first]+p.second);
}
}
}
}
vector<int>todo1,todo2;
for(auto i:v)
{
auto p=que[i];
if(p.first<m*k&&p.second>=(m+1)*k)
{
int res=INT_MAX;
for(int j=0;j<k;j++)
{
if(pom[j][p.first]!=INT_MAX&&pom[j][p.second]!=INT_MAX)
{
res=min(res,pom[j][p.first]+pom[j][p.second]);
}
}
if(res!=INT_MAX)ans[i]=res;
}
else if(p.first/k==m&&p.second>=(m+1)*k)
{
if(pom[p.first%k][p.second]!=INT_MAX)
{
ans[i]=pom[p.first%k][p.second];
}
}
else if(p.second/k==m&&p.first<m*k)
{
if(pom[p.second%k][p.first]!=INT_MAX)
{
ans[i]=pom[p.second%k][p.first];
}
}
else if(p.second/k<m)
{
todo1.push_back(i);
}
else if(p.first/k>m)
{
todo2.push_back(i);
}
}
m=(l+r)/2;
daq(l,m,todo1);
daq(m+1,r,todo2);
}
int main()
{
int m,a,b,c;
cin>>k>>n>>m>>q;
vector<int>todo;
for(int i=0;i<k;i++)
{
pom[i].resize(n);
}
for(int i=0;i<m;i++)
{
cin>>a>>b>>c;
g[a].push_back({b,c});
}
for(int i=0;i<q;i++)
{
ans.push_back(-1);
cin>>a>>b;
que.push_back({a,b});
if(a/k!=b/k)
{
todo.push_back(i);
}
}
daq(0,n-1,todo);
for(int i=0;i<q;i++)
{
cout<<ans[i]<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
4436 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
3 ms |
1628 KB |
Output is correct |
6 |
Correct |
5 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
43 ms |
4432 KB |
Output is correct |
9 |
Correct |
44 ms |
4432 KB |
Output is correct |
10 |
Correct |
17 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
5404 KB |
Output is correct |
2 |
Correct |
1 ms |
1376 KB |
Output is correct |
3 |
Correct |
1 ms |
1584 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
1416 KB |
Output is correct |
6 |
Correct |
1 ms |
1368 KB |
Output is correct |
7 |
Correct |
22 ms |
1884 KB |
Output is correct |
8 |
Correct |
14 ms |
2140 KB |
Output is correct |
9 |
Correct |
52 ms |
4496 KB |
Output is correct |
10 |
Correct |
133 ms |
7192 KB |
Output is correct |
11 |
Correct |
82 ms |
5460 KB |
Output is correct |
12 |
Correct |
73 ms |
5124 KB |
Output is correct |
13 |
Correct |
114 ms |
7252 KB |
Output is correct |
14 |
Correct |
99 ms |
4940 KB |
Output is correct |
15 |
Correct |
96 ms |
4688 KB |
Output is correct |
16 |
Correct |
57 ms |
4716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1368 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
3 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
33 ms |
3988 KB |
Output is correct |
11 |
Correct |
90 ms |
4952 KB |
Output is correct |
12 |
Correct |
89 ms |
6736 KB |
Output is correct |
13 |
Correct |
95 ms |
7256 KB |
Output is correct |
14 |
Correct |
80 ms |
5948 KB |
Output is correct |
15 |
Correct |
55 ms |
4688 KB |
Output is correct |
16 |
Correct |
56 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1368 KB |
Output is correct |
5 |
Correct |
1 ms |
1372 KB |
Output is correct |
6 |
Correct |
3 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1628 KB |
Output is correct |
10 |
Correct |
33 ms |
3988 KB |
Output is correct |
11 |
Correct |
90 ms |
4952 KB |
Output is correct |
12 |
Correct |
89 ms |
6736 KB |
Output is correct |
13 |
Correct |
95 ms |
7256 KB |
Output is correct |
14 |
Correct |
80 ms |
5948 KB |
Output is correct |
15 |
Correct |
55 ms |
4688 KB |
Output is correct |
16 |
Correct |
56 ms |
4436 KB |
Output is correct |
17 |
Correct |
100 ms |
5200 KB |
Output is correct |
18 |
Correct |
1 ms |
1368 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1372 KB |
Output is correct |
21 |
Correct |
1 ms |
1372 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
6 ms |
1884 KB |
Output is correct |
24 |
Correct |
5 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1884 KB |
Output is correct |
26 |
Correct |
6 ms |
1848 KB |
Output is correct |
27 |
Correct |
35 ms |
4164 KB |
Output is correct |
28 |
Correct |
96 ms |
6872 KB |
Output is correct |
29 |
Correct |
111 ms |
7416 KB |
Output is correct |
30 |
Correct |
120 ms |
6240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
4436 KB |
Output is correct |
2 |
Correct |
1 ms |
1372 KB |
Output is correct |
3 |
Correct |
1 ms |
1372 KB |
Output is correct |
4 |
Correct |
1 ms |
1372 KB |
Output is correct |
5 |
Correct |
3 ms |
1628 KB |
Output is correct |
6 |
Correct |
5 ms |
1628 KB |
Output is correct |
7 |
Correct |
2 ms |
1628 KB |
Output is correct |
8 |
Correct |
43 ms |
4432 KB |
Output is correct |
9 |
Correct |
44 ms |
4432 KB |
Output is correct |
10 |
Correct |
17 ms |
2136 KB |
Output is correct |
11 |
Correct |
83 ms |
5404 KB |
Output is correct |
12 |
Correct |
1 ms |
1376 KB |
Output is correct |
13 |
Correct |
1 ms |
1584 KB |
Output is correct |
14 |
Correct |
1 ms |
1372 KB |
Output is correct |
15 |
Correct |
1 ms |
1416 KB |
Output is correct |
16 |
Correct |
1 ms |
1368 KB |
Output is correct |
17 |
Correct |
22 ms |
1884 KB |
Output is correct |
18 |
Correct |
14 ms |
2140 KB |
Output is correct |
19 |
Correct |
52 ms |
4496 KB |
Output is correct |
20 |
Correct |
133 ms |
7192 KB |
Output is correct |
21 |
Correct |
82 ms |
5460 KB |
Output is correct |
22 |
Correct |
73 ms |
5124 KB |
Output is correct |
23 |
Correct |
114 ms |
7252 KB |
Output is correct |
24 |
Correct |
99 ms |
4940 KB |
Output is correct |
25 |
Correct |
96 ms |
4688 KB |
Output is correct |
26 |
Correct |
57 ms |
4716 KB |
Output is correct |
27 |
Correct |
1 ms |
1372 KB |
Output is correct |
28 |
Correct |
1 ms |
1372 KB |
Output is correct |
29 |
Correct |
1 ms |
1372 KB |
Output is correct |
30 |
Correct |
1 ms |
1368 KB |
Output is correct |
31 |
Correct |
1 ms |
1372 KB |
Output is correct |
32 |
Correct |
3 ms |
1628 KB |
Output is correct |
33 |
Correct |
2 ms |
1628 KB |
Output is correct |
34 |
Correct |
3 ms |
1628 KB |
Output is correct |
35 |
Correct |
3 ms |
1628 KB |
Output is correct |
36 |
Correct |
33 ms |
3988 KB |
Output is correct |
37 |
Correct |
90 ms |
4952 KB |
Output is correct |
38 |
Correct |
89 ms |
6736 KB |
Output is correct |
39 |
Correct |
95 ms |
7256 KB |
Output is correct |
40 |
Correct |
80 ms |
5948 KB |
Output is correct |
41 |
Correct |
55 ms |
4688 KB |
Output is correct |
42 |
Correct |
56 ms |
4436 KB |
Output is correct |
43 |
Correct |
100 ms |
5200 KB |
Output is correct |
44 |
Correct |
1 ms |
1368 KB |
Output is correct |
45 |
Correct |
1 ms |
1372 KB |
Output is correct |
46 |
Correct |
1 ms |
1372 KB |
Output is correct |
47 |
Correct |
1 ms |
1372 KB |
Output is correct |
48 |
Correct |
1 ms |
1372 KB |
Output is correct |
49 |
Correct |
6 ms |
1884 KB |
Output is correct |
50 |
Correct |
5 ms |
1628 KB |
Output is correct |
51 |
Correct |
6 ms |
1884 KB |
Output is correct |
52 |
Correct |
6 ms |
1848 KB |
Output is correct |
53 |
Correct |
35 ms |
4164 KB |
Output is correct |
54 |
Correct |
96 ms |
6872 KB |
Output is correct |
55 |
Correct |
111 ms |
7416 KB |
Output is correct |
56 |
Correct |
120 ms |
6240 KB |
Output is correct |
57 |
Correct |
142 ms |
8532 KB |
Output is correct |
58 |
Correct |
43 ms |
4432 KB |
Output is correct |
59 |
Correct |
134 ms |
5456 KB |
Output is correct |