답안 #956846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956846 2024-04-02T14:30:08 Z 8pete8 Boat (APIO16_boat) C++17
100 / 100
721 ms 33264 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<numeric> //gcd(a,b)
#include<cmath>
#include<set>
#include<cassert>
#include<algorithm>
#include<bitset> 
#include<stack>
//#include "aliens.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
//#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int int64_t
const int mxn=1000+10,minf=-1e18,mod=1e9+7,inf=1e18,lg=30;
int dp[mxn+10][mxn+10],ncr[mxn+10][mxn+10],sum[mxn+10][mxn+10];
int ncr2[mxn+10][mxn+10];
int choose[mxn+10][mxn+10];
int fac[mxn+10];
int inv(int x){
	int ex=mod-2,ans=1;
	while(ex){
		if(ex&1)ans=(ans*x)%mod;
		x=(x*x)%mod;
		ex>>=1;
	}
	return ans;
}
int32_t main(){
	fastio
	int n;cin>>n;
	vector<pii>v(n+1);
	vector<int>com;
	for(int i=1;i<=n;i++)cin>>v[i].f>>v[i].s,v[i].f--;
	for(int i=1;i<=n;i++)com.pb(v[i].f),com.pb(v[i].s);
	sort(all(com));
	com.erase(unique(all(com)),com.end());
	/*
	for(auto i:com)cout<<i<<" ";
	cout<<'\n'<<'\n';*/
	/*
	ncr i,j->(i,j+1)
	x=(x*(len-j+1))*inv(j)
	*/
	ncr[0][0]=1;
	for(int i=1;i<=n;i++)for(int j=0;j<=n;j++){
		if(j)ncr[i][j]=(ncr[i-1][j]+ncr[i-1][j-1])%mod;
		else ncr[i][j]=ncr[i-1][j];
	}
	//for(int i=0;i<=n;i++)ncr[0][i]=1;
	for(int i=1;i<com.size();i++){
		int len=com[i]-com[i-1];
		ncr2[i][1]=len;	
		for(int j=2;j<=n;j++)ncr2[i][j]=((ncr2[i][j-1]*(len-j+1))%mod*inv(j))%mod;
	}
	for(int i=1;i<com.size();i++){
		choose[i][1]=ncr2[i][1];
		for(int j=2;j<=n;j++){
			int sum=0;
			//ith segment have j
			//need to fix 2
			//k=use so use 2->min(j,len)
			//
			//cout<<i<<" "<<j<<"G\n";
			for(int k=2;k<=j;k++){
				sum=(sum+(ncr2[i][k]*(ncr[j-2][k-2])%mod))%mod;
				//cout<<ncr2[i][k]<<" "<<ncr[j-2][k]<<"L\n";
				//cout<<sum<<'\n';
			}
			choose[i][j]=sum;
		}
	}
	//cout<<choose[2][2]<<"LL\n";
	for(int i=0;i<=2*n;i++)sum[0][i]=1;
	for(int i=0;i<=2*n;i++)sum[i][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<com.size();j++){
			if(com[j]>v[i].f&&com[j]<=v[i].s){
				if(choose[j][1]==1)dp[i][j]=sum[i-1][j-1];
				else{
					int cnt=0;
					for(int back=i;back>=1;back--){
						if(com[j]>v[back].f&&com[j]<=v[back].s){
							cnt++;
							//cout<<i<<" "<<j<<" "<<back<<" "<<sum[back-1][j-1]<<" "<<choose[j][cnt]<<' '<<cnt<<'\n';
							dp[i][j]=(dp[i][j]+(sum[back-1][j-1]*choose[j][cnt])%mod)%mod;
						}
					}
				}
			}
			sum[i][j]=((dp[i][j]+(sum[i-1][j]+sum[i][j-1])%mod)%mod-sum[i-1][j-1]+mod)%mod;
		}
	}
	/*
	for(int i=1;i<=n;i++){
		for(int j=0;j<com.size();j++)cout<<dp[i][j]<<" ";
		cout<<'\n';
	}*/
	cout<<sum[n][com.size()-1]-1;
}
/*
dp[i][j]->last pick at i and on segment j or less
dp[i][j]->back[j-1]*(len cnt)
we want to compute  (len ,cnt)
=the num of ways to assign each cnt to each val in len

if we know len cnt
then num of ways to assign cnt to len-> ncr(len,cnt)
we also need to fix 2
*/

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:70:15: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for(int i=1;i<com.size();i++){
      |              ~^~~~~~~~~~~
boat.cpp:75:15: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for(int i=1;i<com.size();i++){
      |              ~^~~~~~~~~~~
boat.cpp:96:16: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |   for(int j=1;j<com.size();j++){
      |               ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 30032 KB Output is correct
2 Correct 550 ms 29832 KB Output is correct
3 Correct 543 ms 30864 KB Output is correct
4 Correct 540 ms 30036 KB Output is correct
5 Correct 533 ms 29896 KB Output is correct
6 Correct 534 ms 33184 KB Output is correct
7 Correct 544 ms 29896 KB Output is correct
8 Correct 533 ms 30072 KB Output is correct
9 Correct 533 ms 30036 KB Output is correct
10 Correct 532 ms 30212 KB Output is correct
11 Correct 538 ms 30084 KB Output is correct
12 Correct 535 ms 30116 KB Output is correct
13 Correct 532 ms 30208 KB Output is correct
14 Correct 533 ms 32968 KB Output is correct
15 Correct 534 ms 30064 KB Output is correct
16 Correct 98 ms 21916 KB Output is correct
17 Correct 103 ms 22040 KB Output is correct
18 Correct 100 ms 21904 KB Output is correct
19 Correct 104 ms 21908 KB Output is correct
20 Correct 101 ms 21920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 30032 KB Output is correct
2 Correct 550 ms 29832 KB Output is correct
3 Correct 543 ms 30864 KB Output is correct
4 Correct 540 ms 30036 KB Output is correct
5 Correct 533 ms 29896 KB Output is correct
6 Correct 534 ms 33184 KB Output is correct
7 Correct 544 ms 29896 KB Output is correct
8 Correct 533 ms 30072 KB Output is correct
9 Correct 533 ms 30036 KB Output is correct
10 Correct 532 ms 30212 KB Output is correct
11 Correct 538 ms 30084 KB Output is correct
12 Correct 535 ms 30116 KB Output is correct
13 Correct 532 ms 30208 KB Output is correct
14 Correct 533 ms 32968 KB Output is correct
15 Correct 534 ms 30064 KB Output is correct
16 Correct 98 ms 21916 KB Output is correct
17 Correct 103 ms 22040 KB Output is correct
18 Correct 100 ms 21904 KB Output is correct
19 Correct 104 ms 21908 KB Output is correct
20 Correct 101 ms 21920 KB Output is correct
21 Correct 565 ms 30956 KB Output is correct
22 Correct 566 ms 31000 KB Output is correct
23 Correct 551 ms 31056 KB Output is correct
24 Correct 564 ms 31124 KB Output is correct
25 Correct 568 ms 32300 KB Output is correct
26 Correct 598 ms 30676 KB Output is correct
27 Correct 602 ms 31808 KB Output is correct
28 Correct 631 ms 31668 KB Output is correct
29 Correct 598 ms 31644 KB Output is correct
30 Correct 530 ms 30032 KB Output is correct
31 Correct 546 ms 29932 KB Output is correct
32 Correct 540 ms 30964 KB Output is correct
33 Correct 543 ms 29864 KB Output is correct
34 Correct 538 ms 30072 KB Output is correct
35 Correct 539 ms 31400 KB Output is correct
36 Correct 539 ms 31144 KB Output is correct
37 Correct 546 ms 29868 KB Output is correct
38 Correct 532 ms 29816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15196 KB Output is correct
2 Correct 9 ms 15196 KB Output is correct
3 Correct 10 ms 15192 KB Output is correct
4 Correct 9 ms 15196 KB Output is correct
5 Correct 9 ms 15196 KB Output is correct
6 Correct 10 ms 15196 KB Output is correct
7 Correct 10 ms 15196 KB Output is correct
8 Correct 14 ms 15196 KB Output is correct
9 Correct 14 ms 15196 KB Output is correct
10 Correct 11 ms 15192 KB Output is correct
11 Correct 9 ms 15196 KB Output is correct
12 Correct 10 ms 15192 KB Output is correct
13 Correct 9 ms 15196 KB Output is correct
14 Correct 9 ms 15196 KB Output is correct
15 Correct 9 ms 15196 KB Output is correct
16 Correct 6 ms 15196 KB Output is correct
17 Correct 6 ms 15196 KB Output is correct
18 Correct 6 ms 15196 KB Output is correct
19 Correct 6 ms 15324 KB Output is correct
20 Correct 6 ms 15196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 30032 KB Output is correct
2 Correct 550 ms 29832 KB Output is correct
3 Correct 543 ms 30864 KB Output is correct
4 Correct 540 ms 30036 KB Output is correct
5 Correct 533 ms 29896 KB Output is correct
6 Correct 534 ms 33184 KB Output is correct
7 Correct 544 ms 29896 KB Output is correct
8 Correct 533 ms 30072 KB Output is correct
9 Correct 533 ms 30036 KB Output is correct
10 Correct 532 ms 30212 KB Output is correct
11 Correct 538 ms 30084 KB Output is correct
12 Correct 535 ms 30116 KB Output is correct
13 Correct 532 ms 30208 KB Output is correct
14 Correct 533 ms 32968 KB Output is correct
15 Correct 534 ms 30064 KB Output is correct
16 Correct 98 ms 21916 KB Output is correct
17 Correct 103 ms 22040 KB Output is correct
18 Correct 100 ms 21904 KB Output is correct
19 Correct 104 ms 21908 KB Output is correct
20 Correct 101 ms 21920 KB Output is correct
21 Correct 565 ms 30956 KB Output is correct
22 Correct 566 ms 31000 KB Output is correct
23 Correct 551 ms 31056 KB Output is correct
24 Correct 564 ms 31124 KB Output is correct
25 Correct 568 ms 32300 KB Output is correct
26 Correct 598 ms 30676 KB Output is correct
27 Correct 602 ms 31808 KB Output is correct
28 Correct 631 ms 31668 KB Output is correct
29 Correct 598 ms 31644 KB Output is correct
30 Correct 530 ms 30032 KB Output is correct
31 Correct 546 ms 29932 KB Output is correct
32 Correct 540 ms 30964 KB Output is correct
33 Correct 543 ms 29864 KB Output is correct
34 Correct 538 ms 30072 KB Output is correct
35 Correct 539 ms 31400 KB Output is correct
36 Correct 539 ms 31144 KB Output is correct
37 Correct 546 ms 29868 KB Output is correct
38 Correct 532 ms 29816 KB Output is correct
39 Correct 9 ms 15196 KB Output is correct
40 Correct 9 ms 15196 KB Output is correct
41 Correct 10 ms 15192 KB Output is correct
42 Correct 9 ms 15196 KB Output is correct
43 Correct 9 ms 15196 KB Output is correct
44 Correct 10 ms 15196 KB Output is correct
45 Correct 10 ms 15196 KB Output is correct
46 Correct 14 ms 15196 KB Output is correct
47 Correct 14 ms 15196 KB Output is correct
48 Correct 11 ms 15192 KB Output is correct
49 Correct 9 ms 15196 KB Output is correct
50 Correct 10 ms 15192 KB Output is correct
51 Correct 9 ms 15196 KB Output is correct
52 Correct 9 ms 15196 KB Output is correct
53 Correct 9 ms 15196 KB Output is correct
54 Correct 6 ms 15196 KB Output is correct
55 Correct 6 ms 15196 KB Output is correct
56 Correct 6 ms 15196 KB Output is correct
57 Correct 6 ms 15324 KB Output is correct
58 Correct 6 ms 15196 KB Output is correct
59 Correct 634 ms 32420 KB Output is correct
60 Correct 620 ms 32420 KB Output is correct
61 Correct 628 ms 32328 KB Output is correct
62 Correct 628 ms 32340 KB Output is correct
63 Correct 630 ms 32260 KB Output is correct
64 Correct 721 ms 33064 KB Output is correct
65 Correct 711 ms 33104 KB Output is correct
66 Correct 721 ms 33264 KB Output is correct
67 Correct 711 ms 33168 KB Output is correct
68 Correct 719 ms 33192 KB Output is correct
69 Correct 604 ms 32420 KB Output is correct
70 Correct 611 ms 32252 KB Output is correct
71 Correct 609 ms 32248 KB Output is correct
72 Correct 608 ms 32252 KB Output is correct
73 Correct 609 ms 32244 KB Output is correct
74 Correct 109 ms 23208 KB Output is correct
75 Correct 112 ms 23376 KB Output is correct
76 Correct 112 ms 23380 KB Output is correct
77 Correct 112 ms 23380 KB Output is correct
78 Correct 111 ms 23380 KB Output is correct