답안 #44896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44896 2018-04-09T06:42:27 Z Kerim Boat (APIO16_boat) C++17
36 / 100
91 ms 2244 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=505;
map<int,int>vis;
map<int,vector<int> >add,rem;
set<int>s;
vector<int>v;
int arr[N],inv[N],par[N],dp[N],DP[N][N];
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]);
	}
}
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:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
boat.cpp:67: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 Correct 37 ms 1656 KB Output is correct
2 Correct 30 ms 1656 KB Output is correct
3 Correct 35 ms 1708 KB Output is correct
4 Correct 32 ms 1784 KB Output is correct
5 Correct 31 ms 1900 KB Output is correct
6 Correct 33 ms 2116 KB Output is correct
7 Correct 31 ms 2116 KB Output is correct
8 Correct 33 ms 2116 KB Output is correct
9 Correct 31 ms 2116 KB Output is correct
10 Correct 33 ms 2116 KB Output is correct
11 Correct 32 ms 2116 KB Output is correct
12 Correct 30 ms 2116 KB Output is correct
13 Correct 34 ms 2136 KB Output is correct
14 Correct 31 ms 2136 KB Output is correct
15 Correct 31 ms 2136 KB Output is correct
16 Correct 8 ms 2136 KB Output is correct
17 Correct 8 ms 2136 KB Output is correct
18 Correct 8 ms 2136 KB Output is correct
19 Correct 9 ms 2136 KB Output is correct
20 Correct 8 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1656 KB Output is correct
2 Correct 30 ms 1656 KB Output is correct
3 Correct 35 ms 1708 KB Output is correct
4 Correct 32 ms 1784 KB Output is correct
5 Correct 31 ms 1900 KB Output is correct
6 Correct 33 ms 2116 KB Output is correct
7 Correct 31 ms 2116 KB Output is correct
8 Correct 33 ms 2116 KB Output is correct
9 Correct 31 ms 2116 KB Output is correct
10 Correct 33 ms 2116 KB Output is correct
11 Correct 32 ms 2116 KB Output is correct
12 Correct 30 ms 2116 KB Output is correct
13 Correct 34 ms 2136 KB Output is correct
14 Correct 31 ms 2136 KB Output is correct
15 Correct 31 ms 2136 KB Output is correct
16 Correct 8 ms 2136 KB Output is correct
17 Correct 8 ms 2136 KB Output is correct
18 Correct 8 ms 2136 KB Output is correct
19 Correct 9 ms 2136 KB Output is correct
20 Correct 8 ms 2168 KB Output is correct
21 Incorrect 91 ms 2180 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2180 KB Output is correct
2 Correct 17 ms 2180 KB Output is correct
3 Correct 19 ms 2180 KB Output is correct
4 Correct 18 ms 2180 KB Output is correct
5 Correct 19 ms 2180 KB Output is correct
6 Correct 29 ms 2180 KB Output is correct
7 Correct 23 ms 2180 KB Output is correct
8 Correct 23 ms 2180 KB Output is correct
9 Correct 23 ms 2180 KB Output is correct
10 Correct 24 ms 2180 KB Output is correct
11 Correct 18 ms 2180 KB Output is correct
12 Correct 16 ms 2180 KB Output is correct
13 Correct 20 ms 2180 KB Output is correct
14 Correct 17 ms 2180 KB Output is correct
15 Correct 18 ms 2180 KB Output is correct
16 Correct 11 ms 2244 KB Output is correct
17 Correct 11 ms 2244 KB Output is correct
18 Correct 11 ms 2244 KB Output is correct
19 Correct 11 ms 2244 KB Output is correct
20 Correct 11 ms 2244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1656 KB Output is correct
2 Correct 30 ms 1656 KB Output is correct
3 Correct 35 ms 1708 KB Output is correct
4 Correct 32 ms 1784 KB Output is correct
5 Correct 31 ms 1900 KB Output is correct
6 Correct 33 ms 2116 KB Output is correct
7 Correct 31 ms 2116 KB Output is correct
8 Correct 33 ms 2116 KB Output is correct
9 Correct 31 ms 2116 KB Output is correct
10 Correct 33 ms 2116 KB Output is correct
11 Correct 32 ms 2116 KB Output is correct
12 Correct 30 ms 2116 KB Output is correct
13 Correct 34 ms 2136 KB Output is correct
14 Correct 31 ms 2136 KB Output is correct
15 Correct 31 ms 2136 KB Output is correct
16 Correct 8 ms 2136 KB Output is correct
17 Correct 8 ms 2136 KB Output is correct
18 Correct 8 ms 2136 KB Output is correct
19 Correct 9 ms 2136 KB Output is correct
20 Correct 8 ms 2168 KB Output is correct
21 Incorrect 91 ms 2180 KB Output isn't correct
22 Halted 0 ms 0 KB -