# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
843053 |
2023-09-03T15:31:19 Z |
ASN49K |
Toll (BOI17_toll) |
C++14 |
|
182 ms |
90844 KB |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <set>
#include <functional>
#include <bitset>
#include <map>
#include <unordered_map>
#include <queue>
#include <array>
#include <numeric>
#include <complex>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename A> ostream& operator<<(ostream& os, vector<A>& a) { for(auto &c:a)os<<c<<' '; return os;}
template<typename A> istream& operator>>(istream& os, vector<A>& a) { for(auto &c:a)os>>c; return os;}
template<typename A,size_t N> istream& operator>>(istream &os, array<A,N>&a) { for(auto &c:a)os>>c; return os;}
template<typename A,typename B> istream& operator>>(istream& os, pair<A,B>&a) { os>>a.first>>a.second; return os;}
template<typename A> istream& operator >>(istream& os,complex<A>& a){pair<A,A>aux;os>>aux;a=complex<A>(aux.first,aux.second);return os;}
#define bug(a) cerr << "(" << #a << ": " << a << ")\n";
#define all(x) x.begin(),x.end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PQ priority_queue
#define x real
#define y imag
using pii= pair<int,int>;
using VI= vector<int>;
using v64= vector<int64_t>;
using point=complex<double>;
using i64= int64_t;
using i16= int16_t;
using u64= uint64_t;
using u32= uint32_t;
using i32= int32_t;
using u16= uint16_t;
const i32 inf=1e9;
const i64 INF=1e18;
const int mod=1e9+7;
const int sigma=26;
///sparse table dp[(int)log2(saritura)][poz/k][x][y]
#define vvii vector<vector<int>>
void solve()
{
int k,n,m,q;
cin>>k>>n>>m>>q;
int mx_jump=(n-1)/k;
//position of last element
vector<vector<vector<vector<int>>>>dp((int)20,vector<vector<vector<int>>>(mx_jump+1,vector<vector<int>>(k,vector<int>(k,inf))));
for(int i=0;i<m;i++)
{
int x,y,z;
cin>>x>>y>>z;
dp[0][x/k][x%k][y%k]=z;
}
auto combine=[&](const vvii& x,const vvii& y)
{
vvii sol(k,vector<int>(k,inf));
for(int i=0;i<k;i++)
{
for(int j=0;j<k;j++)
{
for(int m=0;m<k;m++)
{
sol[i][j]=min(sol[i][j],x[i][m]+y[m][j]);
}
}
}
return sol;
};
for(int i=1;(1<<i)-1<=mx_jump;i++)
{
for(int j=0;j+(1<<i)-1<=mx_jump;j++)
{
dp[i][j]=combine(dp[i-1][j],dp[i-1][j+(1<<(i-1))]);
}
}
while(q--)
{
int x,y;
cin>>x>>y;
vector<int> sol(k,inf);
sol[x%k]=0;
int caut=y%k;
x/=k;
y/=k;
if(x!=y)
{
for(int i=(int)log2(y-x);i>=0;i--)
{
if(x+(1<<i)<=y)
{
auto old=sol;
fill(all(sol),inf);
for(int a=0;a<k;a++)
{
for(int b=0;b<k;b++)
{
sol[b]=min(sol[b],old[a]+dp[i][x][a][b]);
}
}
x+=(1<<i);
}
}
}
if(sol[caut]==inf)
sol[caut]=-1;
cout<<sol[caut]<<'\n';
}
}
main()
{
i32 tt=1;
ios::sync_with_stdio(false);
cin.tie(0);
//cin>>tt;
while(tt--)
{
solve();
}
}
Compilation message
toll.cpp:118:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
118 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
90704 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
2264 KB |
Output is correct |
6 |
Correct |
3 ms |
2140 KB |
Output is correct |
7 |
Correct |
3 ms |
2140 KB |
Output is correct |
8 |
Correct |
152 ms |
90668 KB |
Output is correct |
9 |
Correct |
151 ms |
90660 KB |
Output is correct |
10 |
Correct |
148 ms |
90704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
78420 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
2260 KB |
Output is correct |
8 |
Correct |
6 ms |
2140 KB |
Output is correct |
9 |
Correct |
182 ms |
90644 KB |
Output is correct |
10 |
Correct |
130 ms |
70800 KB |
Output is correct |
11 |
Correct |
126 ms |
79504 KB |
Output is correct |
12 |
Correct |
113 ms |
69880 KB |
Output is correct |
13 |
Correct |
98 ms |
41140 KB |
Output is correct |
14 |
Correct |
72 ms |
42600 KB |
Output is correct |
15 |
Correct |
73 ms |
39876 KB |
Output is correct |
16 |
Correct |
69 ms |
39876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
2140 KB |
Output is correct |
7 |
Correct |
2 ms |
2044 KB |
Output is correct |
8 |
Correct |
2 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
133 ms |
90844 KB |
Output is correct |
11 |
Correct |
115 ms |
79508 KB |
Output is correct |
12 |
Correct |
114 ms |
70744 KB |
Output is correct |
13 |
Correct |
120 ms |
71000 KB |
Output is correct |
14 |
Correct |
123 ms |
70396 KB |
Output is correct |
15 |
Correct |
67 ms |
39904 KB |
Output is correct |
16 |
Correct |
67 ms |
40000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
2140 KB |
Output is correct |
7 |
Correct |
2 ms |
2044 KB |
Output is correct |
8 |
Correct |
2 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1628 KB |
Output is correct |
10 |
Correct |
133 ms |
90844 KB |
Output is correct |
11 |
Correct |
115 ms |
79508 KB |
Output is correct |
12 |
Correct |
114 ms |
70744 KB |
Output is correct |
13 |
Correct |
120 ms |
71000 KB |
Output is correct |
14 |
Correct |
123 ms |
70396 KB |
Output is correct |
15 |
Correct |
67 ms |
39904 KB |
Output is correct |
16 |
Correct |
67 ms |
40000 KB |
Output is correct |
17 |
Correct |
120 ms |
79368 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
2140 KB |
Output is correct |
24 |
Correct |
5 ms |
1884 KB |
Output is correct |
25 |
Correct |
4 ms |
1744 KB |
Output is correct |
26 |
Correct |
3 ms |
1884 KB |
Output is correct |
27 |
Correct |
149 ms |
90708 KB |
Output is correct |
28 |
Correct |
120 ms |
70600 KB |
Output is correct |
29 |
Correct |
125 ms |
71004 KB |
Output is correct |
30 |
Correct |
115 ms |
70376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
90704 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
2264 KB |
Output is correct |
6 |
Correct |
3 ms |
2140 KB |
Output is correct |
7 |
Correct |
3 ms |
2140 KB |
Output is correct |
8 |
Correct |
152 ms |
90668 KB |
Output is correct |
9 |
Correct |
151 ms |
90660 KB |
Output is correct |
10 |
Correct |
148 ms |
90704 KB |
Output is correct |
11 |
Correct |
142 ms |
78420 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
6 ms |
2260 KB |
Output is correct |
18 |
Correct |
6 ms |
2140 KB |
Output is correct |
19 |
Correct |
182 ms |
90644 KB |
Output is correct |
20 |
Correct |
130 ms |
70800 KB |
Output is correct |
21 |
Correct |
126 ms |
79504 KB |
Output is correct |
22 |
Correct |
113 ms |
69880 KB |
Output is correct |
23 |
Correct |
98 ms |
41140 KB |
Output is correct |
24 |
Correct |
72 ms |
42600 KB |
Output is correct |
25 |
Correct |
73 ms |
39876 KB |
Output is correct |
26 |
Correct |
69 ms |
39876 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
2140 KB |
Output is correct |
33 |
Correct |
2 ms |
2044 KB |
Output is correct |
34 |
Correct |
2 ms |
1628 KB |
Output is correct |
35 |
Correct |
2 ms |
1628 KB |
Output is correct |
36 |
Correct |
133 ms |
90844 KB |
Output is correct |
37 |
Correct |
115 ms |
79508 KB |
Output is correct |
38 |
Correct |
114 ms |
70744 KB |
Output is correct |
39 |
Correct |
120 ms |
71000 KB |
Output is correct |
40 |
Correct |
123 ms |
70396 KB |
Output is correct |
41 |
Correct |
67 ms |
39904 KB |
Output is correct |
42 |
Correct |
67 ms |
40000 KB |
Output is correct |
43 |
Correct |
120 ms |
79368 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
5 ms |
2140 KB |
Output is correct |
50 |
Correct |
5 ms |
1884 KB |
Output is correct |
51 |
Correct |
4 ms |
1744 KB |
Output is correct |
52 |
Correct |
3 ms |
1884 KB |
Output is correct |
53 |
Correct |
149 ms |
90708 KB |
Output is correct |
54 |
Correct |
120 ms |
70600 KB |
Output is correct |
55 |
Correct |
125 ms |
71004 KB |
Output is correct |
56 |
Correct |
115 ms |
70376 KB |
Output is correct |
57 |
Correct |
146 ms |
71212 KB |
Output is correct |
58 |
Correct |
149 ms |
90692 KB |
Output is correct |
59 |
Correct |
134 ms |
79760 KB |
Output is correct |