# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
979337 |
2024-05-10T16:35:16 Z |
lftroq |
Toll (BOI17_toll) |
C++14 |
|
60 ms |
83636 KB |
/*
:-=-
:%@@@@@@@@@=
.#@@@@@%@%@@@@@@=
-@@@@@@@@@@@@@@@@@#
.+@@@@@@@@@@@@@@@@@@@@.
#@@@@@@@@@@@@@@@@@@@@@%
.*@@@@@@@@@@@@@@@@@@@@@@@= / ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\
.@@@@@@@@@@@@@@@@@@@@@@@@# | lftroq ♥ |
+@@@@@@@@@@@%%@@@@@@@@@@@@- \_________/
.%@@@@@@@@@@%##%@@@@@@@@@@@# //
-@@@@@@@@%%%%%%%%%@@@@@@@@@@:
-+- =@@@@@%##%#%##**+#@@@@@@@@@@-
.+++.%@@@%##%%%%%%%#**+##%%@@@@@@+
+=*%@@@#*###%%#=--+=+*##%@@@@@@%.
:*+%@@*+**##*=======+***#@@@@@@@:
=+++**%@###*=++=-==++**#@@@@@@@:
.**===*%@@@##+=**#*==***@@@@@@@@@:
:+++=+*+%%@@%#==+*%#*+=++@@@@@@@@%
.**#*+*+**+%#+=---=***+==*@@@@@@@:
:**#*+=+**@%##*%#++++--=++#@@@@@@@+-::.
=%**###**#@@%*=*%%%%%*==++++%@@@@@@#=-----.
.%@@%***###@@@%*++%%%#*===+=++++%@@@@%*=-----=.
=**##+=+##@@@@=+%+=***#%@#+**++++%@@%+=-------=:
.++===++====@@@@+--==-=#%%%%+++*++++#%+=------==+=.
-++--=++-:::::=#@#----+--*%%*+**+++++++==-----===--+=
:*+=--++-::::::--=-----==-=%==+%%***++=---=---===-=++:
:*+--+=-::::::::---:----+=-=++##***===-::::-+----=*+:
.=--:::.:::-=-::---::--------++--=====-::::--:-==++
:=::::::--::::::--=+-:--++++==++--==:::-:::----==+=
*-:::::::.....:-++++++++++++++=+=---::::===-:------
:+:--:......:-+++++++++++++++++====---:--=-=----:-:=.
:==--:::.:=+++++++++++++++++++++-::===-:-===-----=--:
.+=--:::-:=+++++==++++++++++++++=--:.:-===+-------+=-.
.+==-----::-+++-:+++=====+++++++=--=======--:----==+=.
:+===-----------:-++====+++++++++=--==--+-:------==-::
+=====-::----+-::-+====+++++++++++=---==:-===:-==-==.
:+===========+-::::-----+++++++++++*=--======-=+=-=.
.=========++=-::::::----:::-++++++*+=+======+++==.
.=========-::::::-----:::=+++++**+=+**====-:. .
*======-::::::::-:-----++++++++==++++++-
#======-:::::::::-------++++++++====+++=
=======-:::::::::----:::=+++++++=====+++
=====---:::::::::::------=++++++===+==++=
:===-:--:::::::::::-------+++++++===++=++
.===-:--:::::::::::::-----=+++++====++===.
.+=-::--::::::::::::-:-----++++++====++=+:
.=-:::--::::::::::::-------=+++++===-----+=
.=-:::--:::::::::::---------=++++==-----==+=.
.=-:::---:::::::::::---------+++===-----===++.
.=::::---:::::::-:-----------=++==-:-----===+-
.--:::---:::::::--------------=+=----==--===+-
.=::::---::::::::::-------===--==-------=--==:
.=--::--::::----:---:::::-:----:::-----======-
.=---:--:::---::::::--------------------==++++
*/
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007ll
#define MOD2 998244353ll
#define endl '\n'
#define PI acos(-1)
#define INFINITE 1000000000
#define INFINITE2 1000000000000000000ll
#define llll pair<ll,ll>
#define ldld pair<ld,ld>
#define fi first
#define se second
#define sqrt sqrtl
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
int k,n,m,q;
int dp[17][50005][5][5],ans[5][5],temp[5][5];
void solve()
{
cin >> k >> n >> m >> q;
for(int i=0;i<17;i++) for(int j=0;j<=(n+k-1)/k;j++) for(int h=0;h<k;h++) for(int l=0;l<k;l++) dp[i][j][h][l]=INFINITE;
while(m--)
{
int u,v,w;
cin >> u >> v >> w;
dp[0][u/k][u%k][v%k]=w;
}
for(int i=1;i<17;i++)
{
for(int j=0;j+(1<<i)+1<=(n+k-1)/k;j++)
{
for(int u=0;u<k;u++)
{
for(int v=0;v<k;v++)
{
for(int t=0;t<k;t++) dp[i][j][u][v]=min(dp[i][j][u][v],dp[i-1][j][u][t]+dp[i-1][j+(1<<(i-1))][t][v]);
}
}
}
}
while(q--)
{
int a,b;
cin >> a >> b;
for(int i=0;i<k;i++)
{
for(int j=0;j<k;j++) ans[i][j]=INFINITE;
ans[i][i]=0;
}
int x=a/k,y=b/k;
for(int i=16;i>=0;i--)
{
if(x+(1<<i)<=y)
{
for(int u=0;u<k;u++) for(int v=0;v<k;v++) temp[u][v]=INFINITE;
for(int u=0;u<k;u++) for(int v=0;v<k;v++) for(int t=0;t<k;t++) temp[u][v]=min(temp[u][v],ans[u][t]+dp[i][x][t][v]);
for(int u=0;u<k;u++) for(int v=0;v<k;v++) ans[u][v]=temp[u][v];
x+=(1<<i);
}
}
if(ans[a%k][b%k]==INFINITE) cout << -1 << endl; else cout << ans[a%k][b%k] << endl;
}
}
int main()
{
fastIO
//freopen("hanhhhh.inp","r",stdin);
//freopen("hanhhhh.out","w",stdout);
int t=1;
//cin >> t;
while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
83536 KB |
Output is correct |
2 |
Correct |
4 ms |
33116 KB |
Output is correct |
3 |
Correct |
4 ms |
33116 KB |
Output is correct |
4 |
Correct |
4 ms |
33276 KB |
Output is correct |
5 |
Correct |
5 ms |
35420 KB |
Output is correct |
6 |
Correct |
4 ms |
35420 KB |
Output is correct |
7 |
Correct |
4 ms |
35420 KB |
Output is correct |
8 |
Correct |
36 ms |
83636 KB |
Output is correct |
9 |
Correct |
36 ms |
83548 KB |
Output is correct |
10 |
Correct |
22 ms |
83548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
76544 KB |
Output is correct |
2 |
Correct |
4 ms |
33116 KB |
Output is correct |
3 |
Correct |
4 ms |
33116 KB |
Output is correct |
4 |
Correct |
4 ms |
33116 KB |
Output is correct |
5 |
Correct |
4 ms |
33116 KB |
Output is correct |
6 |
Correct |
4 ms |
33116 KB |
Output is correct |
7 |
Correct |
8 ms |
35420 KB |
Output is correct |
8 |
Correct |
8 ms |
35420 KB |
Output is correct |
9 |
Correct |
34 ms |
83632 KB |
Output is correct |
10 |
Correct |
46 ms |
62044 KB |
Output is correct |
11 |
Correct |
38 ms |
76628 KB |
Output is correct |
12 |
Correct |
35 ms |
62044 KB |
Output is correct |
13 |
Correct |
44 ms |
43612 KB |
Output is correct |
14 |
Correct |
28 ms |
51804 KB |
Output is correct |
15 |
Correct |
31 ms |
43608 KB |
Output is correct |
16 |
Correct |
31 ms |
43732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
33112 KB |
Output is correct |
2 |
Correct |
4 ms |
33116 KB |
Output is correct |
3 |
Correct |
4 ms |
33112 KB |
Output is correct |
4 |
Correct |
4 ms |
33116 KB |
Output is correct |
5 |
Correct |
4 ms |
33268 KB |
Output is correct |
6 |
Correct |
5 ms |
35420 KB |
Output is correct |
7 |
Correct |
5 ms |
35164 KB |
Output is correct |
8 |
Correct |
5 ms |
33324 KB |
Output is correct |
9 |
Correct |
4 ms |
33368 KB |
Output is correct |
10 |
Correct |
31 ms |
83628 KB |
Output is correct |
11 |
Correct |
31 ms |
76380 KB |
Output is correct |
12 |
Correct |
38 ms |
62040 KB |
Output is correct |
13 |
Correct |
44 ms |
62044 KB |
Output is correct |
14 |
Correct |
35 ms |
62044 KB |
Output is correct |
15 |
Correct |
29 ms |
43612 KB |
Output is correct |
16 |
Correct |
28 ms |
43608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
33112 KB |
Output is correct |
2 |
Correct |
4 ms |
33116 KB |
Output is correct |
3 |
Correct |
4 ms |
33112 KB |
Output is correct |
4 |
Correct |
4 ms |
33116 KB |
Output is correct |
5 |
Correct |
4 ms |
33268 KB |
Output is correct |
6 |
Correct |
5 ms |
35420 KB |
Output is correct |
7 |
Correct |
5 ms |
35164 KB |
Output is correct |
8 |
Correct |
5 ms |
33324 KB |
Output is correct |
9 |
Correct |
4 ms |
33368 KB |
Output is correct |
10 |
Correct |
31 ms |
83628 KB |
Output is correct |
11 |
Correct |
31 ms |
76380 KB |
Output is correct |
12 |
Correct |
38 ms |
62040 KB |
Output is correct |
13 |
Correct |
44 ms |
62044 KB |
Output is correct |
14 |
Correct |
35 ms |
62044 KB |
Output is correct |
15 |
Correct |
29 ms |
43612 KB |
Output is correct |
16 |
Correct |
28 ms |
43608 KB |
Output is correct |
17 |
Correct |
35 ms |
76376 KB |
Output is correct |
18 |
Correct |
4 ms |
33112 KB |
Output is correct |
19 |
Correct |
4 ms |
33116 KB |
Output is correct |
20 |
Correct |
4 ms |
33112 KB |
Output is correct |
21 |
Correct |
4 ms |
33244 KB |
Output is correct |
22 |
Correct |
4 ms |
33112 KB |
Output is correct |
23 |
Correct |
5 ms |
35416 KB |
Output is correct |
24 |
Correct |
5 ms |
35420 KB |
Output is correct |
25 |
Correct |
7 ms |
33116 KB |
Output is correct |
26 |
Correct |
6 ms |
33116 KB |
Output is correct |
27 |
Correct |
32 ms |
83548 KB |
Output is correct |
28 |
Correct |
41 ms |
62044 KB |
Output is correct |
29 |
Correct |
43 ms |
62044 KB |
Output is correct |
30 |
Correct |
37 ms |
62172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
83536 KB |
Output is correct |
2 |
Correct |
4 ms |
33116 KB |
Output is correct |
3 |
Correct |
4 ms |
33116 KB |
Output is correct |
4 |
Correct |
4 ms |
33276 KB |
Output is correct |
5 |
Correct |
5 ms |
35420 KB |
Output is correct |
6 |
Correct |
4 ms |
35420 KB |
Output is correct |
7 |
Correct |
4 ms |
35420 KB |
Output is correct |
8 |
Correct |
36 ms |
83636 KB |
Output is correct |
9 |
Correct |
36 ms |
83548 KB |
Output is correct |
10 |
Correct |
22 ms |
83548 KB |
Output is correct |
11 |
Correct |
38 ms |
76544 KB |
Output is correct |
12 |
Correct |
4 ms |
33116 KB |
Output is correct |
13 |
Correct |
4 ms |
33116 KB |
Output is correct |
14 |
Correct |
4 ms |
33116 KB |
Output is correct |
15 |
Correct |
4 ms |
33116 KB |
Output is correct |
16 |
Correct |
4 ms |
33116 KB |
Output is correct |
17 |
Correct |
8 ms |
35420 KB |
Output is correct |
18 |
Correct |
8 ms |
35420 KB |
Output is correct |
19 |
Correct |
34 ms |
83632 KB |
Output is correct |
20 |
Correct |
46 ms |
62044 KB |
Output is correct |
21 |
Correct |
38 ms |
76628 KB |
Output is correct |
22 |
Correct |
35 ms |
62044 KB |
Output is correct |
23 |
Correct |
44 ms |
43612 KB |
Output is correct |
24 |
Correct |
28 ms |
51804 KB |
Output is correct |
25 |
Correct |
31 ms |
43608 KB |
Output is correct |
26 |
Correct |
31 ms |
43732 KB |
Output is correct |
27 |
Correct |
4 ms |
33112 KB |
Output is correct |
28 |
Correct |
4 ms |
33116 KB |
Output is correct |
29 |
Correct |
4 ms |
33112 KB |
Output is correct |
30 |
Correct |
4 ms |
33116 KB |
Output is correct |
31 |
Correct |
4 ms |
33268 KB |
Output is correct |
32 |
Correct |
5 ms |
35420 KB |
Output is correct |
33 |
Correct |
5 ms |
35164 KB |
Output is correct |
34 |
Correct |
5 ms |
33324 KB |
Output is correct |
35 |
Correct |
4 ms |
33368 KB |
Output is correct |
36 |
Correct |
31 ms |
83628 KB |
Output is correct |
37 |
Correct |
31 ms |
76380 KB |
Output is correct |
38 |
Correct |
38 ms |
62040 KB |
Output is correct |
39 |
Correct |
44 ms |
62044 KB |
Output is correct |
40 |
Correct |
35 ms |
62044 KB |
Output is correct |
41 |
Correct |
29 ms |
43612 KB |
Output is correct |
42 |
Correct |
28 ms |
43608 KB |
Output is correct |
43 |
Correct |
35 ms |
76376 KB |
Output is correct |
44 |
Correct |
4 ms |
33112 KB |
Output is correct |
45 |
Correct |
4 ms |
33116 KB |
Output is correct |
46 |
Correct |
4 ms |
33112 KB |
Output is correct |
47 |
Correct |
4 ms |
33244 KB |
Output is correct |
48 |
Correct |
4 ms |
33112 KB |
Output is correct |
49 |
Correct |
5 ms |
35416 KB |
Output is correct |
50 |
Correct |
5 ms |
35420 KB |
Output is correct |
51 |
Correct |
7 ms |
33116 KB |
Output is correct |
52 |
Correct |
6 ms |
33116 KB |
Output is correct |
53 |
Correct |
32 ms |
83548 KB |
Output is correct |
54 |
Correct |
41 ms |
62044 KB |
Output is correct |
55 |
Correct |
43 ms |
62044 KB |
Output is correct |
56 |
Correct |
37 ms |
62172 KB |
Output is correct |
57 |
Correct |
60 ms |
54100 KB |
Output is correct |
58 |
Correct |
36 ms |
83620 KB |
Output is correct |
59 |
Correct |
43 ms |
76560 KB |
Output is correct |