제출 #354364

#제출 시각아이디문제언어결과실행 시간메모리
354364KerimRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
246 ms31708 KiB
#include "railroad.h"
#include "bits/stdc++.h"
#define MAXN 400009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const ll B=1e15;
ll dp[1<<16][16];
vector<int>s,t;
int n,all;
ll rec(int mask,int last){
	if(mask==all)
		return 0;
	ll &ret=dp[mask][last];
	if(~ret)return ret;ret=B;
	for(int i=0;i<n;i++)
		if(!(mask>>i&1))
			umin(ret,rec(mask|(1<<i),i)+max(0,t[last]-s[i]));
	return ret;
}
vector<int>adj[MAXN];
int par[MAXN],ata[MAXN];
int tap(int x){
	if(ata[x]==x)return x;
	return ata[x]=tap(ata[x]);	
}
bool merge(int x,int y){
	if((x=tap(x))==(y=tap(y)))return 0;
	ata[y]=x;return 1;	
}
long long plan_roller_coaster(vector<int> si, vector<int> ti) {
	s=si;t=ti;
    n = (int) s.size();
    if(n<=16){
    	memset(dp,-1,sizeof dp);
    	all=(1<<n)-1;
    	ll ans=B;
    	for(int i=0;i<n;i++)
    		umin(ans,rec((1<<i),i));
    	return ans;
    }
    vector<int>v;v.pb(1);
    for(int i=0;i<n;i++)
    	v.pb(s[i]),v.pb(t[i]);
    sort(all(v));v.erase(unique(all(v)),v.end());
    for(int i=0;i<n;i++){
    	s[i]=lower_bound(all(v),s[i])-v.begin();	
    	t[i]=lower_bound(all(v),t[i])-v.begin();
    	s[i]++;t[i]++;
    	if(s[i]<t[i])
    		par[s[i]]++,par[t[i]]--;
    	if(s[i]>t[i])
    		par[t[i]]--,par[s[i]]++;
		adj[s[i]].pb(t[i]);	
    }n=int(v.size());
    adj[n].pb(1);
    par[1]--;int sum=0;
    ll ans=0;
    vector<pair<int,PII> >edge;
    for(int i=1;i<n;i++){
    	sum+=par[i];
    	if(sum==0)
    		edge.pb(mp(v[i]-v[i-1],mp(i,i+1)));
    	if(sum>0)
    		ans+=sum*1LL*(v[i]-v[i-1]);
    	if(sum<0)
    		adj[i].pb(i+1);	
    }
    for(int i=1;i<=n;i++)ata[i]=i;
    sort(all(edge));
    tr(it,edge)
    	if(merge(it->ss.ff,it->ss.ss))
    		ans+=it->ff;
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

railroad.cpp: In function 'll rec(int, int)':
railroad.cpp:29:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   29 |  if(~ret)return ret;ret=B;
      |  ^~
railroad.cpp:29:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   29 |  if(~ret)return ret;ret=B;
      |                     ^~~
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:66:6: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   66 |      if(s[i]>t[i])
      |      ^~
railroad.cpp:68:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   68 |   adj[s[i]].pb(t[i]);
      |   ^~~
railroad.cpp:10:18: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   10 | #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
      |                  ^~~
railroad.cpp:85:5: note: in expansion of macro 'tr'
   85 |     tr(it,edge)
      |     ^~
railroad.cpp:88:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   88 |  return ans;
      |  ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...