답안 #44895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44895 2018-04-09T06:36:54 Z Kerim Boat (APIO16_boat) C++17
0 / 100
2000 ms 98680 KB
#include "bits/stdc++.h"
#define MAXN 100009
#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 next nasa
#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 int N=5005;
map<int,int>vis;
map<int,vector<int> >add,rem;
set<int>s;
int arr[N],inv[N],par[MAXN],dp[MAXN];
int mod(ll x){
	while(x<0)
		x+=INF;
	return (x%INF);	
}
int Fe(int x,int y){
	if(!y)
		return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)
		h=mod(h*1LL*x);
	return h;	
}
void pre(int x,int y){
	arr[0]=1;
	for(int i=1;i<=min(x,y);i++){
		arr[i]=mod(arr[i-1]*1LL*x);x--;
		arr[i]=mod(arr[i]*1LL*inv[i]);
	}
}
vector<int>v;
int DP[N][N];
int rec(int x,int y){
	if(x<0)
		return 0;
	int &ret=DP[x][y];
	if(~ret)
		return ret;
	if(!y)
		return ret=mod(rec(x-1,y)+par[v[x]-1]);
	return ret=mod(rec(x-1,y)+rec(x-1,y-1));	
}
int main(){
    //~ freopen("file.in", "r", stdin);
    inv[0]=1;
    for(int i=1;i<N;i++)
		inv[i]=Fe(i,INF-2);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		vis[l]=vis[r+1]=1;
		//~ cout<<"add "<<l<<endl;
		//~ cout<<"rem "<<r+1<<endl;
		add[l].pb(i);
		rem[r+1].pb(i);
	}
	dp[0]=1;
	tr(itt,vis){
		int now=itt->ff,next;
		__typeof((vis).begin())tmp=itt;tmp++;
		if(tmp!=vis.end())
			next=tmp->ff;
		else
			break;	
		tr(it,add[now])
			s.insert(*it);
		tr(it,rem[now])
			s.erase(*it);
		if(s.size()){
			int m=s.size();
			pre(next-now,m);
			par[0]=dp[0];
			for(int i=1;i<=n;i++)
				par[i]=mod(par[i-1]+dp[i]);
			v.clear();	
			tr(it,s)
				v.pb(*it);
			memset(DP,-1,sizeof DP);
			for(int i=0;i<m;i++)
				for(int j=0;j<=min(next-now-1,i);j++){
					if(!j)
						dp[v[i]]=mod(dp[v[i]]+mod(arr[j+1]*1LL*par[v[i]-1]));
					else
						dp[v[i]]=mod(dp[v[i]]+mod(arr[j+1]*1LL*rec(i-1,j-1)));
				}
		}	
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=mod(ans+dp[i]);
	printf("%d\n",ans);		
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
boat.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&l,&r);
   ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2063 ms 98680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2063 ms 98680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 98680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2063 ms 98680 KB Time limit exceeded
2 Halted 0 ms 0 KB -