답안 #123849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123849 2019-07-02T07:57:06 Z baluteshih 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
885 ms 87068 KB
#include "crocodile.h"
#include<bits/stdc++.h>
#define MP make_pair
#define F first
#define S second
#define pb push_back
#define MEM(i,j) memset(i,j,sizeof i)
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e18;
vector<pll> G[100005];
pll dp[100005];
bitset<100005> vis;

struct node
{
	ll i;
	node operator+(const node &x)const{
		if(vis[x.i]||vis[i]) return vis[i]?node{x.i}:node{i};
		return dp[x.i].S<dp[i].S?node{x.i}:node{i};
	}
}seg[400005];

void build(int l,int r,int rt)
{
	if(l==r) 
		return seg[rt].i=l,void();
	int m=l+r>>1;
	build(l,m,rt<<1),build(m+1,r,rt<<1|1);
	seg[rt]=seg[rt<<1]+seg[rt<<1|1];
}

void modify(int x,int l,int r,int rt)
{
	if(l==r)
		return;
	int m=l+r>>1;
	if(x<=m) modify(x,l,m,rt<<1);
	else modify(x,m+1,r,rt<<1|1);
	seg[rt]=seg[rt<<1]+seg[rt<<1|1];
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	for(int i=0;i<N;++i)
		dp[i]=MP(INF,INF);
	for(int i=0;i<M;++i)
		G[R[i][0]].pb(MP(L[i],R[i][1])),G[R[i][1]].pb(MP(L[i],R[i][0]));
	for(int i=0;i<K;++i)
		dp[P[i]]=MP(0,0);
	build(0,N-1,1);
	for(int i=0;i<N;++i)
	{
		int mi=seg[1].i;
		vis[mi]=1;
		modify(mi,0,N-1,1);
		for(auto j:G[mi])
			if(!vis[j.S])
			{
				ll x=dp[mi].S+j.F;
				if(x<dp[j.S].F)
					dp[j.S].S=dp[j.S].F,dp[j.S].F=x,modify(j.S,0,N-1,1);
				else if(x<dp[j.S].S)
					dp[j.S].S=x,modify(j.S,0,N-1,1);
			}
	}
	return dp[0].S;
}

Compilation message

crocodile.cpp: In function 'void build(int, int, int)':
crocodile.cpp:34:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m=l+r>>1;
        ~^~
crocodile.cpp: In function 'void modify(int, int, int, int)':
crocodile.cpp:43:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m=l+r>>1;
        ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2808 KB Output is correct
4 Correct 5 ms 2812 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2808 KB Output is correct
4 Correct 5 ms 2812 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 6 ms 3064 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 8 ms 3320 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2808 KB Output is correct
4 Correct 5 ms 2812 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Correct 5 ms 2808 KB Output is correct
8 Correct 5 ms 2808 KB Output is correct
9 Correct 6 ms 3064 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 8 ms 3320 KB Output is correct
13 Correct 7 ms 3448 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 672 ms 65564 KB Output is correct
17 Correct 155 ms 19752 KB Output is correct
18 Correct 196 ms 22264 KB Output is correct
19 Correct 885 ms 87068 KB Output is correct
20 Correct 388 ms 67588 KB Output is correct
21 Correct 67 ms 10452 KB Output is correct
22 Correct 426 ms 64632 KB Output is correct