# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
441346 |
2021-07-05T03:17:14 Z |
cpp219 |
Toll (BOI17_toll) |
C++14 |
|
330 ms |
88020 KB |
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 5e4 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;
vector<ll> g[N];
ll k,n,m,Q,x,y,w,dp[N][17][5][5],tmp[5][5],ans[5][5];
void Reset(ll a[5][5]){
for (ll i = 0;i < k;i++)
for (ll j = 0;j < k;j++) a[i][j] = inf;
}
void Copy(){
for (ll i = 0;i < k;i++)
for (ll j = 0;j < k;j++) ans[i][j] = tmp[i][j];
}
void combine(ll tar[5][5],ll a[5][5],ll b[5][5]){
for (ll i = 0;i < k;i++)
for (ll j = 0;j < k;j++)
for (ll l = 0;l < k;l++){
tar[i][j] = min(tar[i][j],a[i][l] + b[l][j]);
}
}
void out(ll a[5][5]){
for (ll i = 0;i < 5;i++){
for (ll j = 0;j < 5;j++) cout<<a[i][j]<<" ";
cout<<"\n";
}
exit(0);
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>k>>n>>m>>Q;
for (ll i = 0;i < n;i++)
for (ll j = 0;j < 17;j++) Reset(dp[i][j]);
while(m--){
cin>>x>>y>>w;
dp[x/k][0][x%k][y%k] = w;
}
for (ll j = 1;j < 17;j++){
for (ll i = 0;i <= n;i++){
if (i + (1 << (j - 1)) > n) continue;
combine(dp[i][j],dp[i][j - 1],dp[i + (1 << (j - 1))][j - 1]);
}
}
//out(dp[0][0]);
while(Q--){
cin>>x>>y;
ll cur = x/k,tar = y/k; Reset(ans);
for (ll i = 0;i < k;i++) ans[i][i] = 0;
for (ll i = 16;i >= 0;i--){
if (cur + (1 << i) > tar) continue;
//out(dp[cur][i]);
Reset(tmp); combine(tmp,ans,dp[cur][i]); Copy();
cur += (1 << i);
}
if (ans[x % k][y % k] != inf && x/k < y/k) cout<<ans[x % k][y % k];
else cout<<-1; cout<<"\n";
}
}
Compilation message
toll.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization O2
|
toll.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
toll.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
3 | #pragma target ("avx2")
|
toll.cpp: In function 'int main()':
toll.cpp:78:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
78 | else cout<<-1; cout<<"\n";
| ^~~~
toll.cpp:78:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
78 | else cout<<-1; cout<<"\n";
| ^~~~
toll.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
84768 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
3 ms |
3148 KB |
Output is correct |
6 |
Correct |
3 ms |
3148 KB |
Output is correct |
7 |
Correct |
3 ms |
3148 KB |
Output is correct |
8 |
Correct |
100 ms |
84676 KB |
Output is correct |
9 |
Correct |
101 ms |
84676 KB |
Output is correct |
10 |
Correct |
78 ms |
84632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
84680 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
7 ms |
3148 KB |
Output is correct |
8 |
Correct |
8 ms |
3268 KB |
Output is correct |
9 |
Correct |
94 ms |
85480 KB |
Output is correct |
10 |
Correct |
240 ms |
86896 KB |
Output is correct |
11 |
Correct |
183 ms |
86432 KB |
Output is correct |
12 |
Correct |
221 ms |
85952 KB |
Output is correct |
13 |
Correct |
227 ms |
53776 KB |
Output is correct |
14 |
Correct |
142 ms |
52884 KB |
Output is correct |
15 |
Correct |
206 ms |
52604 KB |
Output is correct |
16 |
Correct |
201 ms |
52496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1496 KB |
Output is correct |
6 |
Correct |
2 ms |
3148 KB |
Output is correct |
7 |
Correct |
3 ms |
3148 KB |
Output is correct |
8 |
Correct |
6 ms |
3148 KB |
Output is correct |
9 |
Correct |
4 ms |
3176 KB |
Output is correct |
10 |
Correct |
90 ms |
85444 KB |
Output is correct |
11 |
Correct |
172 ms |
86056 KB |
Output is correct |
12 |
Correct |
233 ms |
86724 KB |
Output is correct |
13 |
Correct |
246 ms |
87036 KB |
Output is correct |
14 |
Correct |
225 ms |
86424 KB |
Output is correct |
15 |
Correct |
209 ms |
52548 KB |
Output is correct |
16 |
Correct |
194 ms |
52564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1484 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1496 KB |
Output is correct |
6 |
Correct |
2 ms |
3148 KB |
Output is correct |
7 |
Correct |
3 ms |
3148 KB |
Output is correct |
8 |
Correct |
6 ms |
3148 KB |
Output is correct |
9 |
Correct |
4 ms |
3176 KB |
Output is correct |
10 |
Correct |
90 ms |
85444 KB |
Output is correct |
11 |
Correct |
172 ms |
86056 KB |
Output is correct |
12 |
Correct |
233 ms |
86724 KB |
Output is correct |
13 |
Correct |
246 ms |
87036 KB |
Output is correct |
14 |
Correct |
225 ms |
86424 KB |
Output is correct |
15 |
Correct |
209 ms |
52548 KB |
Output is correct |
16 |
Correct |
194 ms |
52564 KB |
Output is correct |
17 |
Correct |
176 ms |
86204 KB |
Output is correct |
18 |
Correct |
1 ms |
1484 KB |
Output is correct |
19 |
Correct |
1 ms |
1484 KB |
Output is correct |
20 |
Correct |
1 ms |
1484 KB |
Output is correct |
21 |
Correct |
1 ms |
1484 KB |
Output is correct |
22 |
Correct |
1 ms |
1484 KB |
Output is correct |
23 |
Correct |
4 ms |
3148 KB |
Output is correct |
24 |
Correct |
4 ms |
3172 KB |
Output is correct |
25 |
Correct |
9 ms |
3168 KB |
Output is correct |
26 |
Correct |
7 ms |
3148 KB |
Output is correct |
27 |
Correct |
93 ms |
85420 KB |
Output is correct |
28 |
Correct |
237 ms |
86864 KB |
Output is correct |
29 |
Correct |
246 ms |
87108 KB |
Output is correct |
30 |
Correct |
228 ms |
86468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
84768 KB |
Output is correct |
2 |
Correct |
1 ms |
1484 KB |
Output is correct |
3 |
Correct |
1 ms |
1484 KB |
Output is correct |
4 |
Correct |
1 ms |
1484 KB |
Output is correct |
5 |
Correct |
3 ms |
3148 KB |
Output is correct |
6 |
Correct |
3 ms |
3148 KB |
Output is correct |
7 |
Correct |
3 ms |
3148 KB |
Output is correct |
8 |
Correct |
100 ms |
84676 KB |
Output is correct |
9 |
Correct |
101 ms |
84676 KB |
Output is correct |
10 |
Correct |
78 ms |
84632 KB |
Output is correct |
11 |
Correct |
185 ms |
84680 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1484 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1484 KB |
Output is correct |
16 |
Correct |
1 ms |
1492 KB |
Output is correct |
17 |
Correct |
7 ms |
3148 KB |
Output is correct |
18 |
Correct |
8 ms |
3268 KB |
Output is correct |
19 |
Correct |
94 ms |
85480 KB |
Output is correct |
20 |
Correct |
240 ms |
86896 KB |
Output is correct |
21 |
Correct |
183 ms |
86432 KB |
Output is correct |
22 |
Correct |
221 ms |
85952 KB |
Output is correct |
23 |
Correct |
227 ms |
53776 KB |
Output is correct |
24 |
Correct |
142 ms |
52884 KB |
Output is correct |
25 |
Correct |
206 ms |
52604 KB |
Output is correct |
26 |
Correct |
201 ms |
52496 KB |
Output is correct |
27 |
Correct |
1 ms |
1484 KB |
Output is correct |
28 |
Correct |
1 ms |
1484 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
1 ms |
1484 KB |
Output is correct |
31 |
Correct |
1 ms |
1496 KB |
Output is correct |
32 |
Correct |
2 ms |
3148 KB |
Output is correct |
33 |
Correct |
3 ms |
3148 KB |
Output is correct |
34 |
Correct |
6 ms |
3148 KB |
Output is correct |
35 |
Correct |
4 ms |
3176 KB |
Output is correct |
36 |
Correct |
90 ms |
85444 KB |
Output is correct |
37 |
Correct |
172 ms |
86056 KB |
Output is correct |
38 |
Correct |
233 ms |
86724 KB |
Output is correct |
39 |
Correct |
246 ms |
87036 KB |
Output is correct |
40 |
Correct |
225 ms |
86424 KB |
Output is correct |
41 |
Correct |
209 ms |
52548 KB |
Output is correct |
42 |
Correct |
194 ms |
52564 KB |
Output is correct |
43 |
Correct |
176 ms |
86204 KB |
Output is correct |
44 |
Correct |
1 ms |
1484 KB |
Output is correct |
45 |
Correct |
1 ms |
1484 KB |
Output is correct |
46 |
Correct |
1 ms |
1484 KB |
Output is correct |
47 |
Correct |
1 ms |
1484 KB |
Output is correct |
48 |
Correct |
1 ms |
1484 KB |
Output is correct |
49 |
Correct |
4 ms |
3148 KB |
Output is correct |
50 |
Correct |
4 ms |
3172 KB |
Output is correct |
51 |
Correct |
9 ms |
3168 KB |
Output is correct |
52 |
Correct |
7 ms |
3148 KB |
Output is correct |
53 |
Correct |
93 ms |
85420 KB |
Output is correct |
54 |
Correct |
237 ms |
86864 KB |
Output is correct |
55 |
Correct |
246 ms |
87108 KB |
Output is correct |
56 |
Correct |
228 ms |
86468 KB |
Output is correct |
57 |
Correct |
330 ms |
88020 KB |
Output is correct |
58 |
Correct |
103 ms |
85580 KB |
Output is correct |
59 |
Correct |
181 ms |
86388 KB |
Output is correct |