# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
129360 |
2019-07-12T05:08:27 Z |
davitmarg |
Toll (BOI17_toll) |
C++17 |
|
297 ms |
66908 KB |
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
struct node
{
LL d[6][6];
node()
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
d[i][j]=mod*100005ll;
}
};
LL k,n,m,o;
bool used[50004];
vector<int> a[50004];
vector<pair<int,LL>> g[50004];
node t[4*50004];
node merge(node a,node b,int pos)
{
node r;
for(int s=0;s<k;s++)
for(int e=0;e<k;e++)
for(int v=pos*k;v<pos*k+k;v++)
for(int i=0;i<g[v].size();i++)
{
int to=g[v][i].first;
LL d=g[v][i].second;
r.d[s][e]=min( a.d[s][v-pos*k]+b.d[to-pos*k-k][e]+d ,r.d[s][e]);
}
return r;
}
void build(int v,int l,int r)
{
if(l==r)
{
for(int i=0;i<k;i++)
t[v].d[i][i]=0;
return;
}
int m=(l+r)/2;
build(v*2,l,m);
build(v*2+1,m+1,r);
t[v]=merge(t[v*2],t[v*2+1],m);
}
node get(int v,int l,int r,int i,int j)
{
if(i>j)
return node();
if(l==i && r==j)
return t[v];
int m=(l+r)/2;
if(j<=m)
return get(v*2,l,m,i,j);
else if(i>=m+1)
return get(v*2+1,m+1,r,i,j);
else
return merge(
get(v*2,l,m,i,m),
get(v*2+1,m+1,r,m+1,j),
m
);
}
int main()
{
cin>>k>>n>>m>>o;
while(m--)
{
int a,b;
LL d;
scanf("%d%d%lld",&a,&b,&d);
g[a].PB(MP(b,d));
}
for(int i=0;i<n;i++)
a[i/k].PB(i);
n--;
build(1,0,n/k);
while(o--)
{
int a,b;
scanf("%d%d",&a,&b);
LL ans=get(1,0,n/k,a/k,b/k).d[a-(a/k)*k][b-(b/k)*k];
if(ans>=mod*100005ll)
ans=-1;
printf("%lld\n",ans);
}
return 0;
}
/*
5 14 5 5
0 5 9
5 12 10
0 7 7
7 12 8
4 7 10
0 12
0 5
0 7
7 12
0 13
*/
Compilation message
toll.cpp: In function 'node merge(node, node, int)':
toll.cpp:48:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[v].size();i++)
~^~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld",&a,&b,&d);
~~~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:109:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
63224 KB |
Output is correct |
2 |
Correct |
56 ms |
59000 KB |
Output is correct |
3 |
Correct |
47 ms |
59000 KB |
Output is correct |
4 |
Correct |
47 ms |
59068 KB |
Output is correct |
5 |
Correct |
49 ms |
59180 KB |
Output is correct |
6 |
Correct |
49 ms |
59128 KB |
Output is correct |
7 |
Correct |
49 ms |
59128 KB |
Output is correct |
8 |
Correct |
127 ms |
63096 KB |
Output is correct |
9 |
Correct |
132 ms |
63076 KB |
Output is correct |
10 |
Correct |
87 ms |
60792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
63864 KB |
Output is correct |
2 |
Correct |
48 ms |
59000 KB |
Output is correct |
3 |
Correct |
47 ms |
59000 KB |
Output is correct |
4 |
Correct |
49 ms |
59188 KB |
Output is correct |
5 |
Correct |
48 ms |
59128 KB |
Output is correct |
6 |
Correct |
47 ms |
59000 KB |
Output is correct |
7 |
Correct |
56 ms |
59228 KB |
Output is correct |
8 |
Correct |
58 ms |
59256 KB |
Output is correct |
9 |
Correct |
113 ms |
63088 KB |
Output is correct |
10 |
Correct |
178 ms |
65696 KB |
Output is correct |
11 |
Correct |
137 ms |
63992 KB |
Output is correct |
12 |
Correct |
125 ms |
62840 KB |
Output is correct |
13 |
Correct |
171 ms |
66124 KB |
Output is correct |
14 |
Correct |
112 ms |
63224 KB |
Output is correct |
15 |
Correct |
136 ms |
62504 KB |
Output is correct |
16 |
Correct |
297 ms |
62456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
58972 KB |
Output is correct |
2 |
Correct |
47 ms |
59004 KB |
Output is correct |
3 |
Correct |
47 ms |
59000 KB |
Output is correct |
4 |
Correct |
48 ms |
59000 KB |
Output is correct |
5 |
Correct |
56 ms |
59128 KB |
Output is correct |
6 |
Correct |
57 ms |
59128 KB |
Output is correct |
7 |
Correct |
48 ms |
59128 KB |
Output is correct |
8 |
Correct |
51 ms |
59256 KB |
Output is correct |
9 |
Correct |
55 ms |
59256 KB |
Output is correct |
10 |
Correct |
94 ms |
62968 KB |
Output is correct |
11 |
Correct |
119 ms |
63708 KB |
Output is correct |
12 |
Correct |
136 ms |
65320 KB |
Output is correct |
13 |
Correct |
143 ms |
66040 KB |
Output is correct |
14 |
Correct |
126 ms |
64444 KB |
Output is correct |
15 |
Correct |
98 ms |
62460 KB |
Output is correct |
16 |
Correct |
96 ms |
62456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
58972 KB |
Output is correct |
2 |
Correct |
47 ms |
59004 KB |
Output is correct |
3 |
Correct |
47 ms |
59000 KB |
Output is correct |
4 |
Correct |
48 ms |
59000 KB |
Output is correct |
5 |
Correct |
56 ms |
59128 KB |
Output is correct |
6 |
Correct |
57 ms |
59128 KB |
Output is correct |
7 |
Correct |
48 ms |
59128 KB |
Output is correct |
8 |
Correct |
51 ms |
59256 KB |
Output is correct |
9 |
Correct |
55 ms |
59256 KB |
Output is correct |
10 |
Correct |
94 ms |
62968 KB |
Output is correct |
11 |
Correct |
119 ms |
63708 KB |
Output is correct |
12 |
Correct |
136 ms |
65320 KB |
Output is correct |
13 |
Correct |
143 ms |
66040 KB |
Output is correct |
14 |
Correct |
126 ms |
64444 KB |
Output is correct |
15 |
Correct |
98 ms |
62460 KB |
Output is correct |
16 |
Correct |
96 ms |
62456 KB |
Output is correct |
17 |
Correct |
125 ms |
63736 KB |
Output is correct |
18 |
Correct |
47 ms |
59004 KB |
Output is correct |
19 |
Correct |
47 ms |
59004 KB |
Output is correct |
20 |
Correct |
47 ms |
59000 KB |
Output is correct |
21 |
Correct |
47 ms |
59004 KB |
Output is correct |
22 |
Correct |
47 ms |
59004 KB |
Output is correct |
23 |
Correct |
52 ms |
59128 KB |
Output is correct |
24 |
Correct |
53 ms |
59256 KB |
Output is correct |
25 |
Correct |
70 ms |
59256 KB |
Output is correct |
26 |
Correct |
61 ms |
59164 KB |
Output is correct |
27 |
Correct |
103 ms |
63096 KB |
Output is correct |
28 |
Correct |
151 ms |
65464 KB |
Output is correct |
29 |
Correct |
162 ms |
66168 KB |
Output is correct |
30 |
Correct |
141 ms |
64308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
63224 KB |
Output is correct |
2 |
Correct |
56 ms |
59000 KB |
Output is correct |
3 |
Correct |
47 ms |
59000 KB |
Output is correct |
4 |
Correct |
47 ms |
59068 KB |
Output is correct |
5 |
Correct |
49 ms |
59180 KB |
Output is correct |
6 |
Correct |
49 ms |
59128 KB |
Output is correct |
7 |
Correct |
49 ms |
59128 KB |
Output is correct |
8 |
Correct |
127 ms |
63096 KB |
Output is correct |
9 |
Correct |
132 ms |
63076 KB |
Output is correct |
10 |
Correct |
87 ms |
60792 KB |
Output is correct |
11 |
Correct |
159 ms |
63864 KB |
Output is correct |
12 |
Correct |
48 ms |
59000 KB |
Output is correct |
13 |
Correct |
47 ms |
59000 KB |
Output is correct |
14 |
Correct |
49 ms |
59188 KB |
Output is correct |
15 |
Correct |
48 ms |
59128 KB |
Output is correct |
16 |
Correct |
47 ms |
59000 KB |
Output is correct |
17 |
Correct |
56 ms |
59228 KB |
Output is correct |
18 |
Correct |
58 ms |
59256 KB |
Output is correct |
19 |
Correct |
113 ms |
63088 KB |
Output is correct |
20 |
Correct |
178 ms |
65696 KB |
Output is correct |
21 |
Correct |
137 ms |
63992 KB |
Output is correct |
22 |
Correct |
125 ms |
62840 KB |
Output is correct |
23 |
Correct |
171 ms |
66124 KB |
Output is correct |
24 |
Correct |
112 ms |
63224 KB |
Output is correct |
25 |
Correct |
136 ms |
62504 KB |
Output is correct |
26 |
Correct |
297 ms |
62456 KB |
Output is correct |
27 |
Correct |
53 ms |
58972 KB |
Output is correct |
28 |
Correct |
47 ms |
59004 KB |
Output is correct |
29 |
Correct |
47 ms |
59000 KB |
Output is correct |
30 |
Correct |
48 ms |
59000 KB |
Output is correct |
31 |
Correct |
56 ms |
59128 KB |
Output is correct |
32 |
Correct |
57 ms |
59128 KB |
Output is correct |
33 |
Correct |
48 ms |
59128 KB |
Output is correct |
34 |
Correct |
51 ms |
59256 KB |
Output is correct |
35 |
Correct |
55 ms |
59256 KB |
Output is correct |
36 |
Correct |
94 ms |
62968 KB |
Output is correct |
37 |
Correct |
119 ms |
63708 KB |
Output is correct |
38 |
Correct |
136 ms |
65320 KB |
Output is correct |
39 |
Correct |
143 ms |
66040 KB |
Output is correct |
40 |
Correct |
126 ms |
64444 KB |
Output is correct |
41 |
Correct |
98 ms |
62460 KB |
Output is correct |
42 |
Correct |
96 ms |
62456 KB |
Output is correct |
43 |
Correct |
125 ms |
63736 KB |
Output is correct |
44 |
Correct |
47 ms |
59004 KB |
Output is correct |
45 |
Correct |
47 ms |
59004 KB |
Output is correct |
46 |
Correct |
47 ms |
59000 KB |
Output is correct |
47 |
Correct |
47 ms |
59004 KB |
Output is correct |
48 |
Correct |
47 ms |
59004 KB |
Output is correct |
49 |
Correct |
52 ms |
59128 KB |
Output is correct |
50 |
Correct |
53 ms |
59256 KB |
Output is correct |
51 |
Correct |
70 ms |
59256 KB |
Output is correct |
52 |
Correct |
61 ms |
59164 KB |
Output is correct |
53 |
Correct |
103 ms |
63096 KB |
Output is correct |
54 |
Correct |
151 ms |
65464 KB |
Output is correct |
55 |
Correct |
162 ms |
66168 KB |
Output is correct |
56 |
Correct |
141 ms |
64308 KB |
Output is correct |
57 |
Correct |
280 ms |
66908 KB |
Output is correct |
58 |
Correct |
127 ms |
63192 KB |
Output is correct |
59 |
Correct |
152 ms |
64120 KB |
Output is correct |