답안 #404010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404010 2021-05-13T16:51:01 Z CSQ31 Toll (BOI17_toll) C++14
15 / 100
190 ms 38668 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){
		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,v0);
	re(m+1,R,v1);
}
int main()
{
	owo
	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<n;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 81 ms 33592 KB Output is correct
2 Correct 16 ms 23772 KB Output is correct
3 Correct 12 ms 23712 KB Output is correct
4 Correct 15 ms 23724 KB Output is correct
5 Correct 13 ms 23684 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 14 ms 23740 KB Output is correct
8 Correct 72 ms 33624 KB Output is correct
9 Correct 67 ms 33488 KB Output is correct
10 Correct 33 ms 30576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 34480 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 13 ms 23740 KB Output is correct
5 Correct 14 ms 23748 KB Output is correct
6 Correct 13 ms 23740 KB Output is correct
7 Incorrect 15 ms 23740 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23740 KB Output is correct
2 Correct 12 ms 23740 KB Output is correct
3 Correct 14 ms 23748 KB Output is correct
4 Correct 12 ms 23712 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 13 ms 23688 KB Output is correct
7 Correct 14 ms 23696 KB Output is correct
8 Correct 17 ms 23728 KB Output is correct
9 Correct 15 ms 23748 KB Output is correct
10 Correct 73 ms 34472 KB Output is correct
11 Correct 127 ms 35208 KB Output is correct
12 Correct 187 ms 37684 KB Output is correct
13 Correct 190 ms 38668 KB Output is correct
14 Correct 152 ms 36268 KB Output is correct
15 Correct 139 ms 30528 KB Output is correct
16 Correct 126 ms 30584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23740 KB Output is correct
2 Correct 12 ms 23740 KB Output is correct
3 Correct 14 ms 23748 KB Output is correct
4 Correct 12 ms 23712 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 13 ms 23688 KB Output is correct
7 Correct 14 ms 23696 KB Output is correct
8 Correct 17 ms 23728 KB Output is correct
9 Correct 15 ms 23748 KB Output is correct
10 Correct 73 ms 34472 KB Output is correct
11 Correct 127 ms 35208 KB Output is correct
12 Correct 187 ms 37684 KB Output is correct
13 Correct 190 ms 38668 KB Output is correct
14 Correct 152 ms 36268 KB Output is correct
15 Correct 139 ms 30528 KB Output is correct
16 Correct 126 ms 30584 KB Output is correct
17 Correct 136 ms 34832 KB Output is correct
18 Correct 13 ms 23748 KB Output is correct
19 Correct 12 ms 23780 KB Output is correct
20 Correct 14 ms 23744 KB Output is correct
21 Correct 15 ms 23740 KB Output is correct
22 Correct 13 ms 23740 KB Output is correct
23 Incorrect 17 ms 23800 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 33592 KB Output is correct
2 Correct 16 ms 23772 KB Output is correct
3 Correct 12 ms 23712 KB Output is correct
4 Correct 15 ms 23724 KB Output is correct
5 Correct 13 ms 23684 KB Output is correct
6 Correct 13 ms 23764 KB Output is correct
7 Correct 14 ms 23740 KB Output is correct
8 Correct 72 ms 33624 KB Output is correct
9 Correct 67 ms 33488 KB Output is correct
10 Correct 33 ms 30576 KB Output is correct
11 Correct 130 ms 34480 KB Output is correct
12 Correct 14 ms 23760 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 13 ms 23740 KB Output is correct
15 Correct 14 ms 23748 KB Output is correct
16 Correct 13 ms 23740 KB Output is correct
17 Incorrect 15 ms 23740 KB Output isn't correct
18 Halted 0 ms 0 KB -