# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101874 |
2024-10-17T05:38:00 Z |
simona1230 |
Toll (BOI17_toll) |
C++17 |
|
3000 ms |
18628 KB |
#include <bits/stdc++.h>
using namespace std;
int k,n,m,o;
vector<pair<int,int> > v[200001],op[200001];
void read()
{
cin>>k>>n>>m>>o;
for(int i=1;i<=m;i++)
{
int a,b,t;
cin>>a>>b>>t;
v[a].push_back({b,t});
op[b].push_back({a,t});
}
}
pair<int,int> q[200001];
long long p[200001];
void subt1()
{
for(int i=0;i<n;i++)
{
p[i+1]=1e9;
for(int j=0;j<v[i].size();j++)
{
long long nb=v[i][j].second;
p[i+1]=min(p[i+1],nb);
}
p[i+1]+=p[i];
}
for(int i=1;i<=o;i++)
if(p[q[i].second]-p[q[i].first]<1e9)cout<<p[q[i].second]-p[q[i].first]<<endl;
else cout<<-1<<endl;
exit(0);
}
long long dp[200001];
void subt2()
{
int lm=n;
for(int i=1;i<n;i++)
{
dp[i]=1e9;
for(int j=0;j<op[i].size();j++)
{
pair<int,long long> nb=op[i][j];
dp[i]=min(dp[i],dp[nb.first]+nb.second);
}
}
for(int i=1;i<=o;i++)
if(dp[q[i].second]<1e9)cout<<dp[q[i].second]<<endl;
else cout<<-1<<endl;
exit(0);
}
int lf=0;
long long dp2[50001];
void print(int a,int b)
{
for(int i=0;i<a;i++)
dp2[i]=1e9;
dp2[a]=0;
for(int i=a+1;i<n;i++)
{
dp2[i]=1e9;
for(int j=0;j<op[i].size();j++)
{
pair<int,long long> nb=op[i][j];
dp2[i]=min(dp2[i],dp2[nb.first]+nb.second);
}
}
if(dp2[b]<1e9)cout<<dp2[b]<<endl;
else cout<<-1<<endl;
}
void solve()
{
for(int i=1;i<=o;i++)
{
cin>>q[i].first>>q[i].second;
lf=max(lf,q[i].first);
}
if(k==1)subt1();
if(lf==0)subt2();
for(int i=1;i<=o;i++)
{
print(q[i].first,q[i].second);
}
}
int main() {
read();
solve();
return 0;
}
Compilation message
toll.cpp: In function 'void subt1()':
toll.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int j=0;j<v[i].size();j++)
| ~^~~~~~~~~~~~
toll.cpp: In function 'void subt2()':
toll.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int j=0;j<op[i].size();j++)
| ~^~~~~~~~~~~~~
toll.cpp:45:9: warning: unused variable 'lm' [-Wunused-variable]
45 | int lm=n;
| ^~
toll.cpp: In function 'void print(int, int)':
toll.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<op[i].size();j++)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
15952 KB |
Output is correct |
2 |
Correct |
3 ms |
12624 KB |
Output is correct |
3 |
Correct |
4 ms |
12624 KB |
Output is correct |
4 |
Correct |
4 ms |
12624 KB |
Output is correct |
5 |
Correct |
6 ms |
12624 KB |
Output is correct |
6 |
Correct |
6 ms |
12792 KB |
Output is correct |
7 |
Correct |
5 ms |
12624 KB |
Output is correct |
8 |
Correct |
53 ms |
15940 KB |
Output is correct |
9 |
Correct |
53 ms |
16112 KB |
Output is correct |
10 |
Correct |
21 ms |
12880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
16200 KB |
Output is correct |
2 |
Correct |
3 ms |
12624 KB |
Output is correct |
3 |
Correct |
5 ms |
12588 KB |
Output is correct |
4 |
Correct |
3 ms |
12476 KB |
Output is correct |
5 |
Correct |
4 ms |
12624 KB |
Output is correct |
6 |
Correct |
4 ms |
12804 KB |
Output is correct |
7 |
Correct |
19 ms |
12624 KB |
Output is correct |
8 |
Correct |
20 ms |
12624 KB |
Output is correct |
9 |
Correct |
64 ms |
16112 KB |
Output is correct |
10 |
Correct |
104 ms |
17924 KB |
Output is correct |
11 |
Correct |
82 ms |
16304 KB |
Output is correct |
12 |
Correct |
84 ms |
15944 KB |
Output is correct |
13 |
Correct |
104 ms |
18248 KB |
Output is correct |
14 |
Correct |
63 ms |
15944 KB |
Output is correct |
15 |
Correct |
53 ms |
15344 KB |
Output is correct |
16 |
Correct |
53 ms |
15432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12624 KB |
Output is correct |
2 |
Correct |
3 ms |
12692 KB |
Output is correct |
3 |
Correct |
5 ms |
12624 KB |
Output is correct |
4 |
Correct |
3 ms |
12472 KB |
Output is correct |
5 |
Correct |
4 ms |
12624 KB |
Output is correct |
6 |
Correct |
5 ms |
12624 KB |
Output is correct |
7 |
Correct |
5 ms |
12624 KB |
Output is correct |
8 |
Correct |
7 ms |
12880 KB |
Output is correct |
9 |
Correct |
6 ms |
12624 KB |
Output is correct |
10 |
Correct |
31 ms |
15952 KB |
Output is correct |
11 |
Correct |
76 ms |
15944 KB |
Output is correct |
12 |
Correct |
109 ms |
17992 KB |
Output is correct |
13 |
Correct |
117 ms |
18504 KB |
Output is correct |
14 |
Correct |
87 ms |
17236 KB |
Output is correct |
15 |
Correct |
65 ms |
15436 KB |
Output is correct |
16 |
Correct |
61 ms |
15376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12624 KB |
Output is correct |
2 |
Correct |
3 ms |
12692 KB |
Output is correct |
3 |
Correct |
5 ms |
12624 KB |
Output is correct |
4 |
Correct |
3 ms |
12472 KB |
Output is correct |
5 |
Correct |
4 ms |
12624 KB |
Output is correct |
6 |
Correct |
5 ms |
12624 KB |
Output is correct |
7 |
Correct |
5 ms |
12624 KB |
Output is correct |
8 |
Correct |
7 ms |
12880 KB |
Output is correct |
9 |
Correct |
6 ms |
12624 KB |
Output is correct |
10 |
Correct |
31 ms |
15952 KB |
Output is correct |
11 |
Correct |
76 ms |
15944 KB |
Output is correct |
12 |
Correct |
109 ms |
17992 KB |
Output is correct |
13 |
Correct |
117 ms |
18504 KB |
Output is correct |
14 |
Correct |
87 ms |
17236 KB |
Output is correct |
15 |
Correct |
65 ms |
15436 KB |
Output is correct |
16 |
Correct |
61 ms |
15376 KB |
Output is correct |
17 |
Correct |
558 ms |
16200 KB |
Output is correct |
18 |
Correct |
4 ms |
12624 KB |
Output is correct |
19 |
Correct |
4 ms |
12624 KB |
Output is correct |
20 |
Correct |
4 ms |
12624 KB |
Output is correct |
21 |
Correct |
4 ms |
12624 KB |
Output is correct |
22 |
Correct |
3 ms |
12624 KB |
Output is correct |
23 |
Correct |
10 ms |
12624 KB |
Output is correct |
24 |
Correct |
15 ms |
12624 KB |
Output is correct |
25 |
Correct |
19 ms |
12880 KB |
Output is correct |
26 |
Correct |
18 ms |
12624 KB |
Output is correct |
27 |
Correct |
37 ms |
15952 KB |
Output is correct |
28 |
Correct |
830 ms |
18004 KB |
Output is correct |
29 |
Correct |
805 ms |
18368 KB |
Output is correct |
30 |
Correct |
815 ms |
17224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
15952 KB |
Output is correct |
2 |
Correct |
3 ms |
12624 KB |
Output is correct |
3 |
Correct |
4 ms |
12624 KB |
Output is correct |
4 |
Correct |
4 ms |
12624 KB |
Output is correct |
5 |
Correct |
6 ms |
12624 KB |
Output is correct |
6 |
Correct |
6 ms |
12792 KB |
Output is correct |
7 |
Correct |
5 ms |
12624 KB |
Output is correct |
8 |
Correct |
53 ms |
15940 KB |
Output is correct |
9 |
Correct |
53 ms |
16112 KB |
Output is correct |
10 |
Correct |
21 ms |
12880 KB |
Output is correct |
11 |
Correct |
86 ms |
16200 KB |
Output is correct |
12 |
Correct |
3 ms |
12624 KB |
Output is correct |
13 |
Correct |
5 ms |
12588 KB |
Output is correct |
14 |
Correct |
3 ms |
12476 KB |
Output is correct |
15 |
Correct |
4 ms |
12624 KB |
Output is correct |
16 |
Correct |
4 ms |
12804 KB |
Output is correct |
17 |
Correct |
19 ms |
12624 KB |
Output is correct |
18 |
Correct |
20 ms |
12624 KB |
Output is correct |
19 |
Correct |
64 ms |
16112 KB |
Output is correct |
20 |
Correct |
104 ms |
17924 KB |
Output is correct |
21 |
Correct |
82 ms |
16304 KB |
Output is correct |
22 |
Correct |
84 ms |
15944 KB |
Output is correct |
23 |
Correct |
104 ms |
18248 KB |
Output is correct |
24 |
Correct |
63 ms |
15944 KB |
Output is correct |
25 |
Correct |
53 ms |
15344 KB |
Output is correct |
26 |
Correct |
53 ms |
15432 KB |
Output is correct |
27 |
Correct |
4 ms |
12624 KB |
Output is correct |
28 |
Correct |
3 ms |
12692 KB |
Output is correct |
29 |
Correct |
5 ms |
12624 KB |
Output is correct |
30 |
Correct |
3 ms |
12472 KB |
Output is correct |
31 |
Correct |
4 ms |
12624 KB |
Output is correct |
32 |
Correct |
5 ms |
12624 KB |
Output is correct |
33 |
Correct |
5 ms |
12624 KB |
Output is correct |
34 |
Correct |
7 ms |
12880 KB |
Output is correct |
35 |
Correct |
6 ms |
12624 KB |
Output is correct |
36 |
Correct |
31 ms |
15952 KB |
Output is correct |
37 |
Correct |
76 ms |
15944 KB |
Output is correct |
38 |
Correct |
109 ms |
17992 KB |
Output is correct |
39 |
Correct |
117 ms |
18504 KB |
Output is correct |
40 |
Correct |
87 ms |
17236 KB |
Output is correct |
41 |
Correct |
65 ms |
15436 KB |
Output is correct |
42 |
Correct |
61 ms |
15376 KB |
Output is correct |
43 |
Correct |
558 ms |
16200 KB |
Output is correct |
44 |
Correct |
4 ms |
12624 KB |
Output is correct |
45 |
Correct |
4 ms |
12624 KB |
Output is correct |
46 |
Correct |
4 ms |
12624 KB |
Output is correct |
47 |
Correct |
4 ms |
12624 KB |
Output is correct |
48 |
Correct |
3 ms |
12624 KB |
Output is correct |
49 |
Correct |
10 ms |
12624 KB |
Output is correct |
50 |
Correct |
15 ms |
12624 KB |
Output is correct |
51 |
Correct |
19 ms |
12880 KB |
Output is correct |
52 |
Correct |
18 ms |
12624 KB |
Output is correct |
53 |
Correct |
37 ms |
15952 KB |
Output is correct |
54 |
Correct |
830 ms |
18004 KB |
Output is correct |
55 |
Correct |
805 ms |
18368 KB |
Output is correct |
56 |
Correct |
815 ms |
17224 KB |
Output is correct |
57 |
Execution timed out |
3062 ms |
18628 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |