답안 #404043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404043 2021-05-13T17:16:40 Z CSQ31 Toll (BOI17_toll) C++14
100 / 100
354 ms 35572 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5;
vector<vector<PII>>adj(MAXN),tadj(MAXN);
vector<int>l(MAXN),r(MAXN);
vector<ll>ans(MAXN,INF);
vii node(100000);
VII lf(5,vector<ll>(100000,INF)),rg(5,vector<ll>(100000,INF));
int n,k,m,o;
void re(int L,int R,vector<int>v){
	if(L > R || v.empty())return;
	if(L == R){
		for(int x:v)ans[x] = -1;
		return;
	}
	int m = (L+R)/2;//compute rg
	for(int i=0;i<k;i++){
		lf[i][node[m][i]] = 0;
		rg[i][node[m][i]] = 0;
		for(PII x:adj[node[m][i]])rg[i][x.fi] = min(rg[i][x.fi],x.se);
		for(int j=m+1;j<R;j++){
			for(int v:node[j]){	
				for(PII x:adj[v]){
					rg[i][x.fi] = min(rg[i][x.fi],rg[i][v]+x.se);
				}
			}
		}
		for(PII x:tadj[node[m][i]])lf[i][x.fi] = min(lf[i][x.fi],x.se);
		for(int j=m-1;j>L;j--){
			for(int v:node[j]){	
				for(PII x:tadj[v]){
					lf[i][x.fi] = min(lf[i][x.fi],lf[i][v]+x.se);
				}
			}
		}		
	}
	vector<int>v0,v1;
	for(int x:v){
		if(l[x]/k <=m && r[x]/k>=m){
			for(int i=0;i<k;i++)ans[x] = min(ans[x],lf[i][l[x]] + rg[i][r[x]]);
		}else if(l[x]/k > m)v1.pb(x);
		else if(r[x]/k < m)v0.pb(x);
		
	}
	for(int i=0;i<k;i++){
		for(int j=L*k;j<(R+1)*k;j++)rg[i][j] = lf[i][j] = INF;
	}
	re(L,m-1,v0);
	re(m+1,R,v1);
}
int main()
{
	cin>>k>>n>>m>>o;
	for(int i=0;i<n;i++)node[i/k].pb(i);
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		adj[a].pb({b,c});
		tadj[b].pb({a,c});
	}
	for(int i=0;i<o;i++)cin>>l[i]>>r[i];
	vector<int>v;
	for(int i=0;i<o;i++)v.pb(i);
	re(0,(n-1)/k,v);
	for(int i=0;i<o;i++){
		if(ans[i] == INF)ans[i] = -1;
	    cout<<ans[i]<<'\n';
	}
	
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 27956 KB Output is correct
2 Correct 12 ms 23740 KB Output is correct
3 Correct 15 ms 23740 KB Output is correct
4 Correct 13 ms 23712 KB Output is correct
5 Correct 16 ms 23800 KB Output is correct
6 Correct 14 ms 23792 KB Output is correct
7 Correct 14 ms 23740 KB Output is correct
8 Correct 91 ms 27868 KB Output is correct
9 Correct 82 ms 27752 KB Output is correct
10 Correct 24 ms 24788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 29108 KB Output is correct
2 Correct 15 ms 23740 KB Output is correct
3 Correct 13 ms 23704 KB Output is correct
4 Correct 14 ms 23792 KB Output is correct
5 Correct 13 ms 23704 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 19 ms 23804 KB Output is correct
8 Correct 20 ms 23872 KB Output is correct
9 Correct 85 ms 28772 KB Output is correct
10 Correct 214 ms 33976 KB Output is correct
11 Correct 158 ms 30956 KB Output is correct
12 Correct 119 ms 29156 KB Output is correct
13 Correct 216 ms 35204 KB Output is correct
14 Correct 141 ms 30160 KB Output is correct
15 Correct 126 ms 28716 KB Output is correct
16 Correct 112 ms 28560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 12 ms 23740 KB Output is correct
3 Correct 12 ms 23740 KB Output is correct
4 Correct 12 ms 23744 KB Output is correct
5 Correct 13 ms 23740 KB Output is correct
6 Correct 13 ms 23740 KB Output is correct
7 Correct 17 ms 23748 KB Output is correct
8 Correct 18 ms 23792 KB Output is correct
9 Correct 19 ms 23740 KB Output is correct
10 Correct 91 ms 27664 KB Output is correct
11 Correct 144 ms 28884 KB Output is correct
12 Correct 250 ms 31392 KB Output is correct
13 Correct 257 ms 32284 KB Output is correct
14 Correct 237 ms 29860 KB Output is correct
15 Correct 153 ms 27384 KB Output is correct
16 Correct 147 ms 27304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 12 ms 23740 KB Output is correct
3 Correct 12 ms 23740 KB Output is correct
4 Correct 12 ms 23744 KB Output is correct
5 Correct 13 ms 23740 KB Output is correct
6 Correct 13 ms 23740 KB Output is correct
7 Correct 17 ms 23748 KB Output is correct
8 Correct 18 ms 23792 KB Output is correct
9 Correct 19 ms 23740 KB Output is correct
10 Correct 91 ms 27664 KB Output is correct
11 Correct 144 ms 28884 KB Output is correct
12 Correct 250 ms 31392 KB Output is correct
13 Correct 257 ms 32284 KB Output is correct
14 Correct 237 ms 29860 KB Output is correct
15 Correct 153 ms 27384 KB Output is correct
16 Correct 147 ms 27304 KB Output is correct
17 Correct 183 ms 28992 KB Output is correct
18 Correct 15 ms 23776 KB Output is correct
19 Correct 13 ms 23700 KB Output is correct
20 Correct 13 ms 23740 KB Output is correct
21 Correct 14 ms 23740 KB Output is correct
22 Correct 13 ms 23740 KB Output is correct
23 Correct 16 ms 23772 KB Output is correct
24 Correct 20 ms 23868 KB Output is correct
25 Correct 19 ms 23840 KB Output is correct
26 Correct 20 ms 23808 KB Output is correct
27 Correct 84 ms 28632 KB Output is correct
28 Correct 250 ms 33684 KB Output is correct
29 Correct 265 ms 34816 KB Output is correct
30 Correct 203 ms 31720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 27956 KB Output is correct
2 Correct 12 ms 23740 KB Output is correct
3 Correct 15 ms 23740 KB Output is correct
4 Correct 13 ms 23712 KB Output is correct
5 Correct 16 ms 23800 KB Output is correct
6 Correct 14 ms 23792 KB Output is correct
7 Correct 14 ms 23740 KB Output is correct
8 Correct 91 ms 27868 KB Output is correct
9 Correct 82 ms 27752 KB Output is correct
10 Correct 24 ms 24788 KB Output is correct
11 Correct 146 ms 29108 KB Output is correct
12 Correct 15 ms 23740 KB Output is correct
13 Correct 13 ms 23704 KB Output is correct
14 Correct 14 ms 23792 KB Output is correct
15 Correct 13 ms 23704 KB Output is correct
16 Correct 12 ms 23740 KB Output is correct
17 Correct 19 ms 23804 KB Output is correct
18 Correct 20 ms 23872 KB Output is correct
19 Correct 85 ms 28772 KB Output is correct
20 Correct 214 ms 33976 KB Output is correct
21 Correct 158 ms 30956 KB Output is correct
22 Correct 119 ms 29156 KB Output is correct
23 Correct 216 ms 35204 KB Output is correct
24 Correct 141 ms 30160 KB Output is correct
25 Correct 126 ms 28716 KB Output is correct
26 Correct 112 ms 28560 KB Output is correct
27 Correct 12 ms 23772 KB Output is correct
28 Correct 12 ms 23740 KB Output is correct
29 Correct 12 ms 23740 KB Output is correct
30 Correct 12 ms 23744 KB Output is correct
31 Correct 13 ms 23740 KB Output is correct
32 Correct 13 ms 23740 KB Output is correct
33 Correct 17 ms 23748 KB Output is correct
34 Correct 18 ms 23792 KB Output is correct
35 Correct 19 ms 23740 KB Output is correct
36 Correct 91 ms 27664 KB Output is correct
37 Correct 144 ms 28884 KB Output is correct
38 Correct 250 ms 31392 KB Output is correct
39 Correct 257 ms 32284 KB Output is correct
40 Correct 237 ms 29860 KB Output is correct
41 Correct 153 ms 27384 KB Output is correct
42 Correct 147 ms 27304 KB Output is correct
43 Correct 183 ms 28992 KB Output is correct
44 Correct 15 ms 23776 KB Output is correct
45 Correct 13 ms 23700 KB Output is correct
46 Correct 13 ms 23740 KB Output is correct
47 Correct 14 ms 23740 KB Output is correct
48 Correct 13 ms 23740 KB Output is correct
49 Correct 16 ms 23772 KB Output is correct
50 Correct 20 ms 23868 KB Output is correct
51 Correct 19 ms 23840 KB Output is correct
52 Correct 20 ms 23808 KB Output is correct
53 Correct 84 ms 28632 KB Output is correct
54 Correct 250 ms 33684 KB Output is correct
55 Correct 265 ms 34816 KB Output is correct
56 Correct 203 ms 31720 KB Output is correct
57 Correct 354 ms 35572 KB Output is correct
58 Correct 98 ms 28772 KB Output is correct
59 Correct 187 ms 30988 KB Output is correct