# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
162478 |
2019-11-08T10:38:56 Z |
MvC |
Toll (BOI17_toll) |
C++11 |
|
3000 ms |
8568 KB |
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=5e4+50;
const int mod=1e9+7;
using namespace std;
int k,n,m,x,y,t,f[nmax],z,i,j,q,g[nmax],u[nmax],c[nmax];
vector<pair<int,int> >a[nmax];
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>k>>n>>m>>q;
while(m--)
{
cin>>x>>y>>t;
a[x].pb(mkp(y,t));
}
for(i=0;i<n;i++)g[i]=u[i]=c[i]=inf;
g[0]=0;
u[0]=0;
c[0]=0;
for(i=0;i<n;i++)
{
if(g[i]==inf)continue;
for(j=0;j<(int)a[i].size();j++)
{
z=a[i][j].fr,t=a[i][j].sc;
g[z]=min(g[z],g[i]+t);
}
}
for(i=0;i<n;i++)
{
if(u[i]==inf)u[i]=i,c[i]=0;
for(j=0;j<(int)a[i].size();j++)
{
z=a[i][j].fr,t=a[i][j].sc;
u[z]=min(u[z],u[i]);
c[z]=min(c[z],c[i]+t);
}
}
while(q--)
{
cin>>x>>y;
if(y/k<=x/k)cout<<-1<<'\n';
else if(!x)
{
if(g[y]==inf)cout<<-1<<'\n';
else cout<<g[y]<<'\n';
}
else if(k==1)
{
if(u[y]>x)cout<<-1<<'\n';
else cout<<c[y]-c[x]<<'\n';
}
else
{
for(i=x;i<=y;i++)f[i]=inf;
f[x]=0;
for(i=x;i<=y;i++)
{
if(f[i]==inf)continue;
for(j=0;j<(int)a[i].size();j++)
{
z=a[i][j].fr,t=a[i][j].sc;
f[z]=min(f[z],f[i]+t);
}
}
if(f[y]==inf)cout<<-1<<'\n';
else cout<<f[y]<<'\n';
}
}
return 0;
}
Compilation message
toll.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
toll.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
3832 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
4 ms |
1656 KB |
Output is correct |
6 |
Correct |
4 ms |
1656 KB |
Output is correct |
7 |
Correct |
4 ms |
1528 KB |
Output is correct |
8 |
Correct |
34 ms |
4604 KB |
Output is correct |
9 |
Correct |
29 ms |
4472 KB |
Output is correct |
10 |
Correct |
7 ms |
2296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
3704 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1528 KB |
Output is correct |
6 |
Correct |
3 ms |
1528 KB |
Output is correct |
7 |
Correct |
6 ms |
1656 KB |
Output is correct |
8 |
Correct |
6 ms |
1656 KB |
Output is correct |
9 |
Correct |
31 ms |
3772 KB |
Output is correct |
10 |
Correct |
71 ms |
4600 KB |
Output is correct |
11 |
Correct |
58 ms |
3744 KB |
Output is correct |
12 |
Correct |
40 ms |
3576 KB |
Output is correct |
13 |
Correct |
76 ms |
4700 KB |
Output is correct |
14 |
Correct |
50 ms |
3624 KB |
Output is correct |
15 |
Correct |
37 ms |
3192 KB |
Output is correct |
16 |
Correct |
39 ms |
3212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
4 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1656 KB |
Output is correct |
6 |
Correct |
4 ms |
1528 KB |
Output is correct |
7 |
Correct |
4 ms |
1656 KB |
Output is correct |
8 |
Correct |
6 ms |
1628 KB |
Output is correct |
9 |
Correct |
5 ms |
1528 KB |
Output is correct |
10 |
Correct |
35 ms |
3704 KB |
Output is correct |
11 |
Correct |
102 ms |
3960 KB |
Output is correct |
12 |
Correct |
127 ms |
4856 KB |
Output is correct |
13 |
Correct |
133 ms |
5084 KB |
Output is correct |
14 |
Correct |
123 ms |
4316 KB |
Output is correct |
15 |
Correct |
71 ms |
3324 KB |
Output is correct |
16 |
Correct |
65 ms |
3344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
4 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1656 KB |
Output is correct |
6 |
Correct |
4 ms |
1528 KB |
Output is correct |
7 |
Correct |
4 ms |
1656 KB |
Output is correct |
8 |
Correct |
6 ms |
1628 KB |
Output is correct |
9 |
Correct |
5 ms |
1528 KB |
Output is correct |
10 |
Correct |
35 ms |
3704 KB |
Output is correct |
11 |
Correct |
102 ms |
3960 KB |
Output is correct |
12 |
Correct |
127 ms |
4856 KB |
Output is correct |
13 |
Correct |
133 ms |
5084 KB |
Output is correct |
14 |
Correct |
123 ms |
4316 KB |
Output is correct |
15 |
Correct |
71 ms |
3324 KB |
Output is correct |
16 |
Correct |
65 ms |
3344 KB |
Output is correct |
17 |
Correct |
1424 ms |
4024 KB |
Output is correct |
18 |
Correct |
3 ms |
1528 KB |
Output is correct |
19 |
Correct |
3 ms |
1528 KB |
Output is correct |
20 |
Correct |
3 ms |
1528 KB |
Output is correct |
21 |
Correct |
3 ms |
1528 KB |
Output is correct |
22 |
Correct |
3 ms |
1528 KB |
Output is correct |
23 |
Correct |
4 ms |
1656 KB |
Output is correct |
24 |
Correct |
15 ms |
1656 KB |
Output is correct |
25 |
Correct |
23 ms |
1656 KB |
Output is correct |
26 |
Correct |
20 ms |
1656 KB |
Output is correct |
27 |
Correct |
29 ms |
3700 KB |
Output is correct |
28 |
Correct |
1652 ms |
4972 KB |
Output is correct |
29 |
Correct |
1720 ms |
5240 KB |
Output is correct |
30 |
Correct |
1064 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
3832 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
4 ms |
1656 KB |
Output is correct |
6 |
Correct |
4 ms |
1656 KB |
Output is correct |
7 |
Correct |
4 ms |
1528 KB |
Output is correct |
8 |
Correct |
34 ms |
4604 KB |
Output is correct |
9 |
Correct |
29 ms |
4472 KB |
Output is correct |
10 |
Correct |
7 ms |
2296 KB |
Output is correct |
11 |
Correct |
50 ms |
3704 KB |
Output is correct |
12 |
Correct |
3 ms |
1528 KB |
Output is correct |
13 |
Correct |
3 ms |
1528 KB |
Output is correct |
14 |
Correct |
3 ms |
1528 KB |
Output is correct |
15 |
Correct |
3 ms |
1528 KB |
Output is correct |
16 |
Correct |
3 ms |
1528 KB |
Output is correct |
17 |
Correct |
6 ms |
1656 KB |
Output is correct |
18 |
Correct |
6 ms |
1656 KB |
Output is correct |
19 |
Correct |
31 ms |
3772 KB |
Output is correct |
20 |
Correct |
71 ms |
4600 KB |
Output is correct |
21 |
Correct |
58 ms |
3744 KB |
Output is correct |
22 |
Correct |
40 ms |
3576 KB |
Output is correct |
23 |
Correct |
76 ms |
4700 KB |
Output is correct |
24 |
Correct |
50 ms |
3624 KB |
Output is correct |
25 |
Correct |
37 ms |
3192 KB |
Output is correct |
26 |
Correct |
39 ms |
3212 KB |
Output is correct |
27 |
Correct |
3 ms |
1528 KB |
Output is correct |
28 |
Correct |
4 ms |
1528 KB |
Output is correct |
29 |
Correct |
3 ms |
1528 KB |
Output is correct |
30 |
Correct |
3 ms |
1528 KB |
Output is correct |
31 |
Correct |
3 ms |
1656 KB |
Output is correct |
32 |
Correct |
4 ms |
1528 KB |
Output is correct |
33 |
Correct |
4 ms |
1656 KB |
Output is correct |
34 |
Correct |
6 ms |
1628 KB |
Output is correct |
35 |
Correct |
5 ms |
1528 KB |
Output is correct |
36 |
Correct |
35 ms |
3704 KB |
Output is correct |
37 |
Correct |
102 ms |
3960 KB |
Output is correct |
38 |
Correct |
127 ms |
4856 KB |
Output is correct |
39 |
Correct |
133 ms |
5084 KB |
Output is correct |
40 |
Correct |
123 ms |
4316 KB |
Output is correct |
41 |
Correct |
71 ms |
3324 KB |
Output is correct |
42 |
Correct |
65 ms |
3344 KB |
Output is correct |
43 |
Correct |
1424 ms |
4024 KB |
Output is correct |
44 |
Correct |
3 ms |
1528 KB |
Output is correct |
45 |
Correct |
3 ms |
1528 KB |
Output is correct |
46 |
Correct |
3 ms |
1528 KB |
Output is correct |
47 |
Correct |
3 ms |
1528 KB |
Output is correct |
48 |
Correct |
3 ms |
1528 KB |
Output is correct |
49 |
Correct |
4 ms |
1656 KB |
Output is correct |
50 |
Correct |
15 ms |
1656 KB |
Output is correct |
51 |
Correct |
23 ms |
1656 KB |
Output is correct |
52 |
Correct |
20 ms |
1656 KB |
Output is correct |
53 |
Correct |
29 ms |
3700 KB |
Output is correct |
54 |
Correct |
1652 ms |
4972 KB |
Output is correct |
55 |
Correct |
1720 ms |
5240 KB |
Output is correct |
56 |
Correct |
1064 ms |
4472 KB |
Output is correct |
57 |
Execution timed out |
3035 ms |
8568 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |