# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
585159 |
2022-06-28T11:14:43 Z |
Huy |
Toll (BOI17_toll) |
C++17 |
|
373 ms |
62136 KB |
#include<bits/stdc++.h>
//#define int long long
#define pii pair<int,ll>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)5e4 + 5;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int infty = 1e15 + 7;
const int base = (int)4e5;
void InputFile()
{
//freopen("scrivener.inp","r",stdin);
//freopen("scrivener.out","w",stdout);
//freopen("test.out","r",stdin);
}
void FastInput()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int k,n,m,o;
ll f[maxN][17][5];
ll jump[maxN][5];
int grp;
map<pii,int> edg;
void Read()
{
cin >> k >> n >> m >> o;
for(int i = 1;i <= m;i++)
{
int a,b,t;
cin >> a >> b >> t;
edg[{a,b}] = edg[{b,a}] = t;
}
}
void Solve()
{
for(int i = n - 1;i >= 0;i--)
{
/// j = 0;
for(int d = 0;d < k;d++)
{
int nxt = (i / k + 1) * k + d;
if(edg.find(make_pair(i,nxt)) == edg.end()) f[i][0][d] = infty;
else f[i][0][d] = edg[{i,nxt}];
}
for(int j = 1;j <= (int)log2(n);j++)
{
for(int d = 0;d < k;d++)
{
f[i][j][d] = infty;
for(int d1 = 0;d1 < k;d1++) /// pre d
{
int nxt = (i / k + (1<<(j-1))) * k + d1;
if(nxt <= n) f[i][j][d] = min(f[i][j][d],f[nxt][j-1][d] + f[i][j-1][d1]);
else
{
f[i][j][d] = min(f[i][j][d],f[i][j-1][d1]);
}
}
}
}
}
while(o--)
{
int x,y;
cin >> x >> y;
if(x > y) cout << -1 <<'\n';
else if(x / k == y / k)
{
if(x == y) cout << 0 <<'\n';
else cout << -1 <<'\n';
}
else
{
int dis = y / k - x / k;
int pre = x / k;
for(int i = (int)log2(n);i >= 0;i--)
{
if(dis & (1 << i))
{
int nxt = pre + (1 << i);
if(pre == x/k)
{
for(int d = 0;d < k;d++)
{
jump[nxt][d] = f[x][i][d];
}
}
else
{
for(int d = 0;d < k;d++)
{
jump[nxt][d] = infty;
for(int d1 = 0;d1 < k;d1++)
{
jump[nxt][d] = min(jump[nxt][d],jump[pre][d1]+f[pre*k+d1][i][d]);
}
}
}
pre = nxt;
}
}
int res = jump[y/k][y%k];
if(res >= infty) res = -1;
cout << res <<'\n';
}
}
//cout <<"dcme"<<' '<< f[4][0][2] <<' '<<'\n';
}
void Debug()
{
}
int32_t main()
{
FastInput();
//InputFile();
//int sub_type;
//cin >> sub_type;
//Sieve();
//Prepare();
int test;
//cin >> test;
test = 1;
while(test--)
//for(int prc = 1; prc <= test; prc++)
{
Read();
Solve();
//Debug();
}
}
Compilation message
toll.cpp:19:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.000000000000007e+15' to '2147483647' [-Woverflow]
19 | const int infty = 1e15 + 7;
| ~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
41836 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
1044 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
2 ms |
1108 KB |
Output is correct |
8 |
Correct |
78 ms |
41804 KB |
Output is correct |
9 |
Correct |
76 ms |
41492 KB |
Output is correct |
10 |
Correct |
32 ms |
35472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
46408 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
1248 KB |
Output is correct |
8 |
Correct |
6 ms |
1364 KB |
Output is correct |
9 |
Correct |
80 ms |
42644 KB |
Output is correct |
10 |
Correct |
239 ms |
53456 KB |
Output is correct |
11 |
Correct |
170 ms |
48848 KB |
Output is correct |
12 |
Correct |
137 ms |
44900 KB |
Output is correct |
13 |
Correct |
258 ms |
41584 KB |
Output is correct |
14 |
Correct |
151 ms |
33380 KB |
Output is correct |
15 |
Correct |
137 ms |
31160 KB |
Output is correct |
16 |
Correct |
124 ms |
31004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
6 ms |
1644 KB |
Output is correct |
9 |
Correct |
5 ms |
1492 KB |
Output is correct |
10 |
Correct |
100 ms |
41800 KB |
Output is correct |
11 |
Correct |
138 ms |
47600 KB |
Output is correct |
12 |
Correct |
232 ms |
53196 KB |
Output is correct |
13 |
Correct |
270 ms |
55264 KB |
Output is correct |
14 |
Correct |
203 ms |
49952 KB |
Output is correct |
15 |
Correct |
139 ms |
30972 KB |
Output is correct |
16 |
Correct |
122 ms |
31092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
6 ms |
1644 KB |
Output is correct |
9 |
Correct |
5 ms |
1492 KB |
Output is correct |
10 |
Correct |
100 ms |
41800 KB |
Output is correct |
11 |
Correct |
138 ms |
47600 KB |
Output is correct |
12 |
Correct |
232 ms |
53196 KB |
Output is correct |
13 |
Correct |
270 ms |
55264 KB |
Output is correct |
14 |
Correct |
203 ms |
49952 KB |
Output is correct |
15 |
Correct |
139 ms |
30972 KB |
Output is correct |
16 |
Correct |
122 ms |
31092 KB |
Output is correct |
17 |
Correct |
148 ms |
47912 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
1108 KB |
Output is correct |
24 |
Correct |
4 ms |
1236 KB |
Output is correct |
25 |
Correct |
5 ms |
1492 KB |
Output is correct |
26 |
Correct |
5 ms |
1492 KB |
Output is correct |
27 |
Correct |
93 ms |
42496 KB |
Output is correct |
28 |
Correct |
225 ms |
53360 KB |
Output is correct |
29 |
Correct |
265 ms |
55444 KB |
Output is correct |
30 |
Correct |
185 ms |
50168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
41836 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
1044 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
2 ms |
1108 KB |
Output is correct |
8 |
Correct |
78 ms |
41804 KB |
Output is correct |
9 |
Correct |
76 ms |
41492 KB |
Output is correct |
10 |
Correct |
32 ms |
35472 KB |
Output is correct |
11 |
Correct |
145 ms |
46408 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
5 ms |
1248 KB |
Output is correct |
18 |
Correct |
6 ms |
1364 KB |
Output is correct |
19 |
Correct |
80 ms |
42644 KB |
Output is correct |
20 |
Correct |
239 ms |
53456 KB |
Output is correct |
21 |
Correct |
170 ms |
48848 KB |
Output is correct |
22 |
Correct |
137 ms |
44900 KB |
Output is correct |
23 |
Correct |
258 ms |
41584 KB |
Output is correct |
24 |
Correct |
151 ms |
33380 KB |
Output is correct |
25 |
Correct |
137 ms |
31160 KB |
Output is correct |
26 |
Correct |
124 ms |
31004 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
1108 KB |
Output is correct |
33 |
Correct |
3 ms |
1236 KB |
Output is correct |
34 |
Correct |
6 ms |
1644 KB |
Output is correct |
35 |
Correct |
5 ms |
1492 KB |
Output is correct |
36 |
Correct |
100 ms |
41800 KB |
Output is correct |
37 |
Correct |
138 ms |
47600 KB |
Output is correct |
38 |
Correct |
232 ms |
53196 KB |
Output is correct |
39 |
Correct |
270 ms |
55264 KB |
Output is correct |
40 |
Correct |
203 ms |
49952 KB |
Output is correct |
41 |
Correct |
139 ms |
30972 KB |
Output is correct |
42 |
Correct |
122 ms |
31092 KB |
Output is correct |
43 |
Correct |
148 ms |
47912 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
3 ms |
1108 KB |
Output is correct |
50 |
Correct |
4 ms |
1236 KB |
Output is correct |
51 |
Correct |
5 ms |
1492 KB |
Output is correct |
52 |
Correct |
5 ms |
1492 KB |
Output is correct |
53 |
Correct |
93 ms |
42496 KB |
Output is correct |
54 |
Correct |
225 ms |
53360 KB |
Output is correct |
55 |
Correct |
265 ms |
55444 KB |
Output is correct |
56 |
Correct |
185 ms |
50168 KB |
Output is correct |
57 |
Correct |
373 ms |
62136 KB |
Output is correct |
58 |
Correct |
85 ms |
42796 KB |
Output is correct |
59 |
Correct |
162 ms |
48820 KB |
Output is correct |