# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
869450 |
2023-11-04T11:32:33 Z |
AndreiBOTO |
Toll (BOI17_toll) |
C++14 |
|
126 ms |
19828 KB |
#include <bits/stdc++.h>
#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
///#include <tryhardmode>
///#include <GODMODE::ON>
using namespace std;
const int NMAX=5e4+5;
const int INF=1e9;
const int KMAX=6;
vector<pair<int,int>>v[NMAX];
int dpst[NMAX][KMAX][KMAX];
int dpdr[NMAX][KMAX][KMAX];
int rez[NMAX];
int n,k;
struct elem{
int st;
int dr;
int ind;
};
vector<elem>query[NMAX];
void divide(int st,int dr)
{
int i,j;
if(st==dr)
{
for(auto i:query[st])
if(i.dr/k==st && i.st==i.dr)
rez[i.ind]=0;
return ;
}
else
{
int mij=st+dr;
mij/=2;
divide(st,mij);
divide(mij+1,dr);
for(int bucket=st;bucket<=mij;bucket++)
for(i=0;i<k;i++)
for(j=0;j<k;j++)
dpst[bucket][i][j]=INF;
for(int bucket=dr;bucket>=mij;bucket--)
for(i=0;i<k;i++)
for(j=0;j<k;j++)
dpdr[bucket][i][j]=INF;
for(i=0;i<k;i++)
dpst[mij][i][i]=dpdr[mij][i][i]=0;
///dpst-> mij....st
///dpdr-> mij....dr
for(int bucket=mij;bucket<dr;bucket++)
{
for(i=0;i<k;i++)
for(j=0;j<k;j++)
for(auto edge:v[bucket*k+j])
{
dpdr[bucket+1][i][edge.first%k]=min(dpdr[bucket+1][i][edge.first%k],
dpdr[bucket][i][j]+edge.second);
}
}
for(int bucket=mij-1;bucket>=st;bucket--)
{
for(i=0;i<k;i++)
for(j=0;j<k;j++)
for(auto edge:v[bucket*k+j])
{
dpst[bucket][i][j]=min(dpst[bucket][i][j],
dpst[bucket+1][i][edge.first%k]+edge.second);
}
}
for(i=st;i<=mij;i++)
for(auto j:query[i])
if(j.dr/k<=dr && j.dr/k>mij)
for(int lup=0;lup<k;lup++)
rez[j.ind]=min(rez[j.ind],dpst[i][lup][j.st%k]+dpdr[j.dr/k][lup][j.dr%k]);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int m,o,i,j;
cin>>k>>n>>m>>o;
for(i=1;i<=m;i++)
{
int x,y,c;
cin>>x>>y>>c;
v[x].push_back(make_pair(y,c));
}
for(i=1;i<=o;i++)
{
int x,y;
cin>>x>>y;
query[x/k].push_back({x,y,i});
rez[i]=INF;
}
divide(0,n/k);
for(i=1;i<=o;i++)
if(rez[i]==INF)
cout<<-1<<"\n";
else
cout<<rez[i]<<"\n";
return 0;
}
Compilation message
toll.cpp:3: warning: ignoring '#pragma optimize GCC' [-Wunknown-pragmas]
3 | #pragma optimize GCC ("Ofast")
|
toll.cpp: In function 'int main()':
toll.cpp:93:15: warning: unused variable 'j' [-Wunused-variable]
93 | int m,o,i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
19792 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
26 ms |
19704 KB |
Output is correct |
9 |
Correct |
25 ms |
19548 KB |
Output is correct |
10 |
Correct |
10 ms |
17500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
16388 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
4 ms |
7152 KB |
Output is correct |
8 |
Correct |
4 ms |
7196 KB |
Output is correct |
9 |
Correct |
25 ms |
19776 KB |
Output is correct |
10 |
Correct |
70 ms |
15896 KB |
Output is correct |
11 |
Correct |
46 ms |
16492 KB |
Output is correct |
12 |
Correct |
42 ms |
13928 KB |
Output is correct |
13 |
Correct |
90 ms |
11860 KB |
Output is correct |
14 |
Correct |
44 ms |
12080 KB |
Output is correct |
15 |
Correct |
46 ms |
9308 KB |
Output is correct |
16 |
Correct |
47 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6844 KB |
Output is correct |
8 |
Correct |
3 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6896 KB |
Output is correct |
10 |
Correct |
24 ms |
19460 KB |
Output is correct |
11 |
Correct |
41 ms |
15800 KB |
Output is correct |
12 |
Correct |
68 ms |
15308 KB |
Output is correct |
13 |
Correct |
78 ms |
16432 KB |
Output is correct |
14 |
Correct |
57 ms |
14676 KB |
Output is correct |
15 |
Correct |
45 ms |
9296 KB |
Output is correct |
16 |
Correct |
45 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
1 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6844 KB |
Output is correct |
8 |
Correct |
3 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6896 KB |
Output is correct |
10 |
Correct |
24 ms |
19460 KB |
Output is correct |
11 |
Correct |
41 ms |
15800 KB |
Output is correct |
12 |
Correct |
68 ms |
15308 KB |
Output is correct |
13 |
Correct |
78 ms |
16432 KB |
Output is correct |
14 |
Correct |
57 ms |
14676 KB |
Output is correct |
15 |
Correct |
45 ms |
9296 KB |
Output is correct |
16 |
Correct |
45 ms |
9308 KB |
Output is correct |
17 |
Correct |
43 ms |
15952 KB |
Output is correct |
18 |
Correct |
1 ms |
7000 KB |
Output is correct |
19 |
Correct |
1 ms |
6748 KB |
Output is correct |
20 |
Correct |
1 ms |
6832 KB |
Output is correct |
21 |
Correct |
1 ms |
6748 KB |
Output is correct |
22 |
Correct |
1 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
7004 KB |
Output is correct |
25 |
Correct |
4 ms |
6848 KB |
Output is correct |
26 |
Correct |
3 ms |
7004 KB |
Output is correct |
27 |
Correct |
24 ms |
19456 KB |
Output is correct |
28 |
Correct |
70 ms |
15400 KB |
Output is correct |
29 |
Correct |
75 ms |
15952 KB |
Output is correct |
30 |
Correct |
57 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
19792 KB |
Output is correct |
2 |
Correct |
1 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
26 ms |
19704 KB |
Output is correct |
9 |
Correct |
25 ms |
19548 KB |
Output is correct |
10 |
Correct |
10 ms |
17500 KB |
Output is correct |
11 |
Correct |
43 ms |
16388 KB |
Output is correct |
12 |
Correct |
1 ms |
6744 KB |
Output is correct |
13 |
Correct |
1 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6748 KB |
Output is correct |
16 |
Correct |
1 ms |
6748 KB |
Output is correct |
17 |
Correct |
4 ms |
7152 KB |
Output is correct |
18 |
Correct |
4 ms |
7196 KB |
Output is correct |
19 |
Correct |
25 ms |
19776 KB |
Output is correct |
20 |
Correct |
70 ms |
15896 KB |
Output is correct |
21 |
Correct |
46 ms |
16492 KB |
Output is correct |
22 |
Correct |
42 ms |
13928 KB |
Output is correct |
23 |
Correct |
90 ms |
11860 KB |
Output is correct |
24 |
Correct |
44 ms |
12080 KB |
Output is correct |
25 |
Correct |
46 ms |
9308 KB |
Output is correct |
26 |
Correct |
47 ms |
9308 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
1 ms |
6748 KB |
Output is correct |
29 |
Correct |
1 ms |
6748 KB |
Output is correct |
30 |
Correct |
1 ms |
6748 KB |
Output is correct |
31 |
Correct |
1 ms |
6748 KB |
Output is correct |
32 |
Correct |
1 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6844 KB |
Output is correct |
34 |
Correct |
3 ms |
6748 KB |
Output is correct |
35 |
Correct |
2 ms |
6896 KB |
Output is correct |
36 |
Correct |
24 ms |
19460 KB |
Output is correct |
37 |
Correct |
41 ms |
15800 KB |
Output is correct |
38 |
Correct |
68 ms |
15308 KB |
Output is correct |
39 |
Correct |
78 ms |
16432 KB |
Output is correct |
40 |
Correct |
57 ms |
14676 KB |
Output is correct |
41 |
Correct |
45 ms |
9296 KB |
Output is correct |
42 |
Correct |
45 ms |
9308 KB |
Output is correct |
43 |
Correct |
43 ms |
15952 KB |
Output is correct |
44 |
Correct |
1 ms |
7000 KB |
Output is correct |
45 |
Correct |
1 ms |
6748 KB |
Output is correct |
46 |
Correct |
1 ms |
6832 KB |
Output is correct |
47 |
Correct |
1 ms |
6748 KB |
Output is correct |
48 |
Correct |
1 ms |
6748 KB |
Output is correct |
49 |
Correct |
2 ms |
6748 KB |
Output is correct |
50 |
Correct |
2 ms |
7004 KB |
Output is correct |
51 |
Correct |
4 ms |
6848 KB |
Output is correct |
52 |
Correct |
3 ms |
7004 KB |
Output is correct |
53 |
Correct |
24 ms |
19456 KB |
Output is correct |
54 |
Correct |
70 ms |
15400 KB |
Output is correct |
55 |
Correct |
75 ms |
15952 KB |
Output is correct |
56 |
Correct |
57 ms |
14676 KB |
Output is correct |
57 |
Correct |
126 ms |
14928 KB |
Output is correct |
58 |
Correct |
25 ms |
19828 KB |
Output is correct |
59 |
Correct |
46 ms |
16468 KB |
Output is correct |