답안 #225074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
225074 2020-04-19T09:03:11 Z alishahali1382 Boat (APIO16_boat) C++14
100 / 100
1862 ms 8696 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 510, LOG=20;

ll n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN], B[MAXN];
int dp[2][MAXN*2][MAXN];
ll F[MAXN], I[MAXN];
ll ent[MAXN*2][MAXN];
vector<int> comp;

ll powmod(ll a, ll b){
	ll res=1;
	for (; b; b>>=1, a=a*a%mod) if (b&1) res=res*a%mod;
	return res;
}

int C(int n, int r){
	if (r<0 || r>n) return 0;
	ll res=1;
	for (int i=n; i>n-r; i--) res=res*i%mod;
	return res*I[r]%mod;
}

inline void _add(int &x, int y){
	x+=y;
	if (x>=mod) x-=mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<MAXN; i++) F[i]=F[i-1]*i%mod;
	I[MAXN-1]=powmod(F[MAXN-1], mod-2);
	for (int i=MAXN-1; i; i--) I[i-1]=I[i]*i%mod;
	cin>>n;
	for (int i=1; i<=n; i++){
		cin>>A[i]>>B[i];
		comp.pb(A[i]);
		comp.pb(++B[i]);
	}
	
	comp.pb(0);
	sort(all(comp));
	comp.resize(unique(all(comp))-comp.begin());
	m=comp.size()-1;
	
	for (int i=0; i<m; i++) for (int j=0; j<=n; j++) ent[i][j]=C(comp[i+1]-comp[i], j);
	
	for (int i=1; i<=n; i++){
		A[i]=lower_bound(all(comp), A[i])-comp.begin();
		B[i]=lower_bound(all(comp), B[i])-comp.begin();
	}
	dp[0][0][0]=1;
	int prev=0, curr=1;
	for (int i=1; i<=n; i++){
		memset(dp[curr], 0, sizeof(dp[curr]));
		dp[curr][0][0]=1;
		for (int j=1; j<=m; j++){
			for (int k=1; k<=i; k++){
				dp[curr][j][k]=dp[prev][j][k];
				if (A[i]<=j && j<B[i]){
					if (k>1) _add(dp[curr][j][k], dp[prev][j][k-1]);
					else for (int jj=0; jj<j; jj++) _add(dp[curr][j][k], dp[prev][jj][0]);
				}
			}
			for (int kk=1; kk<=i; kk++) dp[curr][j][0]=(dp[curr][j][0]+dp[curr][j][kk]*ent[j][kk])%mod;
		}
		swap(prev, curr);
	}
	for (int j=1; j<=m; j++) ans=(ans+dp[prev][j][0])%mod;
	cout<<ans<<'\n';
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1188 ms 8580 KB Output is correct
2 Correct 1232 ms 8444 KB Output is correct
3 Correct 1199 ms 8568 KB Output is correct
4 Correct 1176 ms 8696 KB Output is correct
5 Correct 1170 ms 8568 KB Output is correct
6 Correct 1195 ms 8568 KB Output is correct
7 Correct 1157 ms 8440 KB Output is correct
8 Correct 1152 ms 8568 KB Output is correct
9 Correct 1156 ms 8568 KB Output is correct
10 Correct 1153 ms 8568 KB Output is correct
11 Correct 1155 ms 8568 KB Output is correct
12 Correct 1159 ms 8468 KB Output is correct
13 Correct 1231 ms 8572 KB Output is correct
14 Correct 1176 ms 8636 KB Output is correct
15 Correct 1158 ms 8468 KB Output is correct
16 Correct 236 ms 5112 KB Output is correct
17 Correct 278 ms 5244 KB Output is correct
18 Correct 246 ms 5112 KB Output is correct
19 Correct 248 ms 5240 KB Output is correct
20 Correct 278 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1188 ms 8580 KB Output is correct
2 Correct 1232 ms 8444 KB Output is correct
3 Correct 1199 ms 8568 KB Output is correct
4 Correct 1176 ms 8696 KB Output is correct
5 Correct 1170 ms 8568 KB Output is correct
6 Correct 1195 ms 8568 KB Output is correct
7 Correct 1157 ms 8440 KB Output is correct
8 Correct 1152 ms 8568 KB Output is correct
9 Correct 1156 ms 8568 KB Output is correct
10 Correct 1153 ms 8568 KB Output is correct
11 Correct 1155 ms 8568 KB Output is correct
12 Correct 1159 ms 8468 KB Output is correct
13 Correct 1231 ms 8572 KB Output is correct
14 Correct 1176 ms 8636 KB Output is correct
15 Correct 1158 ms 8468 KB Output is correct
16 Correct 236 ms 5112 KB Output is correct
17 Correct 278 ms 5244 KB Output is correct
18 Correct 246 ms 5112 KB Output is correct
19 Correct 248 ms 5240 KB Output is correct
20 Correct 278 ms 5112 KB Output is correct
21 Correct 1000 ms 8064 KB Output is correct
22 Correct 993 ms 8184 KB Output is correct
23 Correct 962 ms 8184 KB Output is correct
24 Correct 954 ms 8184 KB Output is correct
25 Correct 987 ms 8088 KB Output is correct
26 Correct 1000 ms 8056 KB Output is correct
27 Correct 1010 ms 7936 KB Output is correct
28 Correct 991 ms 8020 KB Output is correct
29 Correct 990 ms 8056 KB Output is correct
30 Correct 1112 ms 8568 KB Output is correct
31 Correct 1110 ms 8440 KB Output is correct
32 Correct 1129 ms 8696 KB Output is correct
33 Correct 1116 ms 8568 KB Output is correct
34 Correct 1115 ms 8568 KB Output is correct
35 Correct 1147 ms 8568 KB Output is correct
36 Correct 1169 ms 8656 KB Output is correct
37 Correct 1134 ms 8568 KB Output is correct
38 Correct 1129 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 5248 KB Output is correct
2 Correct 26 ms 5248 KB Output is correct
3 Correct 27 ms 5248 KB Output is correct
4 Correct 28 ms 5248 KB Output is correct
5 Correct 27 ms 5248 KB Output is correct
6 Correct 27 ms 5248 KB Output is correct
7 Correct 27 ms 5248 KB Output is correct
8 Correct 28 ms 5248 KB Output is correct
9 Correct 27 ms 5248 KB Output is correct
10 Correct 33 ms 5248 KB Output is correct
11 Correct 27 ms 5248 KB Output is correct
12 Correct 26 ms 5248 KB Output is correct
13 Correct 29 ms 5248 KB Output is correct
14 Correct 26 ms 5248 KB Output is correct
15 Correct 26 ms 5248 KB Output is correct
16 Correct 20 ms 4864 KB Output is correct
17 Correct 20 ms 4864 KB Output is correct
18 Correct 19 ms 4864 KB Output is correct
19 Correct 22 ms 4864 KB Output is correct
20 Correct 19 ms 4864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1188 ms 8580 KB Output is correct
2 Correct 1232 ms 8444 KB Output is correct
3 Correct 1199 ms 8568 KB Output is correct
4 Correct 1176 ms 8696 KB Output is correct
5 Correct 1170 ms 8568 KB Output is correct
6 Correct 1195 ms 8568 KB Output is correct
7 Correct 1157 ms 8440 KB Output is correct
8 Correct 1152 ms 8568 KB Output is correct
9 Correct 1156 ms 8568 KB Output is correct
10 Correct 1153 ms 8568 KB Output is correct
11 Correct 1155 ms 8568 KB Output is correct
12 Correct 1159 ms 8468 KB Output is correct
13 Correct 1231 ms 8572 KB Output is correct
14 Correct 1176 ms 8636 KB Output is correct
15 Correct 1158 ms 8468 KB Output is correct
16 Correct 236 ms 5112 KB Output is correct
17 Correct 278 ms 5244 KB Output is correct
18 Correct 246 ms 5112 KB Output is correct
19 Correct 248 ms 5240 KB Output is correct
20 Correct 278 ms 5112 KB Output is correct
21 Correct 1000 ms 8064 KB Output is correct
22 Correct 993 ms 8184 KB Output is correct
23 Correct 962 ms 8184 KB Output is correct
24 Correct 954 ms 8184 KB Output is correct
25 Correct 987 ms 8088 KB Output is correct
26 Correct 1000 ms 8056 KB Output is correct
27 Correct 1010 ms 7936 KB Output is correct
28 Correct 991 ms 8020 KB Output is correct
29 Correct 990 ms 8056 KB Output is correct
30 Correct 1112 ms 8568 KB Output is correct
31 Correct 1110 ms 8440 KB Output is correct
32 Correct 1129 ms 8696 KB Output is correct
33 Correct 1116 ms 8568 KB Output is correct
34 Correct 1115 ms 8568 KB Output is correct
35 Correct 1147 ms 8568 KB Output is correct
36 Correct 1169 ms 8656 KB Output is correct
37 Correct 1134 ms 8568 KB Output is correct
38 Correct 1129 ms 8568 KB Output is correct
39 Correct 27 ms 5248 KB Output is correct
40 Correct 26 ms 5248 KB Output is correct
41 Correct 27 ms 5248 KB Output is correct
42 Correct 28 ms 5248 KB Output is correct
43 Correct 27 ms 5248 KB Output is correct
44 Correct 27 ms 5248 KB Output is correct
45 Correct 27 ms 5248 KB Output is correct
46 Correct 28 ms 5248 KB Output is correct
47 Correct 27 ms 5248 KB Output is correct
48 Correct 33 ms 5248 KB Output is correct
49 Correct 27 ms 5248 KB Output is correct
50 Correct 26 ms 5248 KB Output is correct
51 Correct 29 ms 5248 KB Output is correct
52 Correct 26 ms 5248 KB Output is correct
53 Correct 26 ms 5248 KB Output is correct
54 Correct 20 ms 4864 KB Output is correct
55 Correct 20 ms 4864 KB Output is correct
56 Correct 19 ms 4864 KB Output is correct
57 Correct 22 ms 4864 KB Output is correct
58 Correct 19 ms 4864 KB Output is correct
59 Correct 1765 ms 8480 KB Output is correct
60 Correct 1713 ms 8528 KB Output is correct
61 Correct 1707 ms 8556 KB Output is correct
62 Correct 1748 ms 8696 KB Output is correct
63 Correct 1746 ms 8440 KB Output is correct
64 Correct 1862 ms 8480 KB Output is correct
65 Correct 1841 ms 8488 KB Output is correct
66 Correct 1833 ms 8572 KB Output is correct
67 Correct 1842 ms 8448 KB Output is correct
68 Correct 1839 ms 8440 KB Output is correct
69 Correct 1745 ms 8568 KB Output is correct
70 Correct 1696 ms 8568 KB Output is correct
71 Correct 1767 ms 8480 KB Output is correct
72 Correct 1769 ms 8568 KB Output is correct
73 Correct 1748 ms 8568 KB Output is correct
74 Correct 263 ms 5240 KB Output is correct
75 Correct 263 ms 5240 KB Output is correct
76 Correct 269 ms 5112 KB Output is correct
77 Correct 272 ms 5240 KB Output is correct
78 Correct 267 ms 5240 KB Output is correct