답안 #246028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246028 2020-07-08T03:46:37 Z wwdd Boat (APIO16_boat) C++14
100 / 100
614 ms 12664 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 510;
const ll M = 1e9+7;
ll dp[2][MN*2][MN];
ll cof[MN*2][MN];
ll nv[MN],sz[2*MN];
inline ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {ac = mul(ac,b);}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
ll inv(ll v) {return bp(v,M-2);}
void pre(int pct, int n) {
	for(int i=1;i<=n+1;i++) {
		nv[i] = inv(i);
	}
	for(int i=0;i<pct-1;i++) {
		cof[i][0] = sz[i];
	}
	for(int i=1;i<=n;i++) {
		for(int j=0;j<pct-1;j++) {
			cof[j][i] = mul(cof[j][i-1],mul(sz[j]-i,nv[i+1]));
		}
	}
}
ll st[MN],ed[MN];
int main() {
	ll n;
	cin >> n;
	map<ll,ll> bo;
	for(int i=0;i<n;i++) {
		cin >> st[i] >> ed[i];
		bo[st[i]] = -1;
		bo[ed[i]+1] = -1;
	}
	int pct = 0;
	ll ls = -1;
	for(auto& it: bo) {
		it.second = pct;
		if(pct > 0) {
			sz[pct-1] = it.first-ls;
		}
		ls = it.first;
		pct++;
	}
	for(int i=0;i<n;i++) {
		st[i] = bo[st[i]];
		ed[i] = bo[ed[i]+1];
	}
	pre(pct, n);
	int cu = 0;
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++) {
		int nu = 1-cu;
		for(int j=0;j<pct-1;j++) {
			for(int k=0;k<=i;k++) {
				dp[nu][j][k] = dp[cu][j][k];
			}
		}
		ll rs = 1;
		for(int j=0;j<st[i];j++) {
			for(int k=0;k<=i;k++) {
				rs += mul(dp[cu][j][k],cof[j][k]);
				if(rs >= M) {rs -= M;}
			}
		}
		for(int j=st[i];j<ed[i];j++) {
			dp[nu][j][0] += rs;
			if(dp[nu][j][0] >= M) {dp[nu][j][0] -= M;}
			for(int k=0;k<=i;k++) {
				dp[nu][j][k+1] += dp[cu][j][k];
				if(dp[nu][j][k+1] >= M) {
					dp[nu][j][k+1] -= M;
				}
				rs += mul(dp[cu][j][k],cof[j][k]);
				if(rs >= M) {rs -= M;}
			}
		}
		cu = nu;
	}
	ll res = 0;
	for(int i=0;i<pct-1;i++) {
		for(int j=0;j<=n;j++) {
			res += mul(dp[cu][i][j],cof[i][j]);
		}
	}
	res %= M;
	cout << res << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 12544 KB Output is correct
2 Correct 446 ms 12664 KB Output is correct
3 Correct 432 ms 12664 KB Output is correct
4 Correct 614 ms 12544 KB Output is correct
5 Correct 425 ms 12664 KB Output is correct
6 Correct 474 ms 12544 KB Output is correct
7 Correct 494 ms 12588 KB Output is correct
8 Correct 457 ms 12544 KB Output is correct
9 Correct 443 ms 12544 KB Output is correct
10 Correct 441 ms 12664 KB Output is correct
11 Correct 469 ms 12544 KB Output is correct
12 Correct 436 ms 12664 KB Output is correct
13 Correct 444 ms 12664 KB Output is correct
14 Correct 474 ms 12664 KB Output is correct
15 Correct 442 ms 12664 KB Output is correct
16 Correct 53 ms 9216 KB Output is correct
17 Correct 55 ms 9344 KB Output is correct
18 Correct 54 ms 9216 KB Output is correct
19 Correct 55 ms 9216 KB Output is correct
20 Correct 87 ms 9216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 12544 KB Output is correct
2 Correct 446 ms 12664 KB Output is correct
3 Correct 432 ms 12664 KB Output is correct
4 Correct 614 ms 12544 KB Output is correct
5 Correct 425 ms 12664 KB Output is correct
6 Correct 474 ms 12544 KB Output is correct
7 Correct 494 ms 12588 KB Output is correct
8 Correct 457 ms 12544 KB Output is correct
9 Correct 443 ms 12544 KB Output is correct
10 Correct 441 ms 12664 KB Output is correct
11 Correct 469 ms 12544 KB Output is correct
12 Correct 436 ms 12664 KB Output is correct
13 Correct 444 ms 12664 KB Output is correct
14 Correct 474 ms 12664 KB Output is correct
15 Correct 442 ms 12664 KB Output is correct
16 Correct 53 ms 9216 KB Output is correct
17 Correct 55 ms 9344 KB Output is correct
18 Correct 54 ms 9216 KB Output is correct
19 Correct 55 ms 9216 KB Output is correct
20 Correct 87 ms 9216 KB Output is correct
21 Correct 503 ms 12280 KB Output is correct
22 Correct 444 ms 12280 KB Output is correct
23 Correct 432 ms 12280 KB Output is correct
24 Correct 437 ms 12280 KB Output is correct
25 Correct 433 ms 12160 KB Output is correct
26 Correct 491 ms 12032 KB Output is correct
27 Correct 485 ms 12160 KB Output is correct
28 Correct 474 ms 12032 KB Output is correct
29 Correct 495 ms 12152 KB Output is correct
30 Correct 445 ms 12544 KB Output is correct
31 Correct 452 ms 12536 KB Output is correct
32 Correct 492 ms 12664 KB Output is correct
33 Correct 466 ms 12664 KB Output is correct
34 Correct 445 ms 12664 KB Output is correct
35 Correct 393 ms 12664 KB Output is correct
36 Correct 440 ms 12664 KB Output is correct
37 Correct 435 ms 12664 KB Output is correct
38 Correct 402 ms 12544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9344 KB Output is correct
2 Correct 13 ms 9344 KB Output is correct
3 Correct 13 ms 9344 KB Output is correct
4 Correct 19 ms 9344 KB Output is correct
5 Correct 19 ms 9344 KB Output is correct
6 Correct 14 ms 9344 KB Output is correct
7 Correct 13 ms 9344 KB Output is correct
8 Correct 13 ms 9344 KB Output is correct
9 Correct 13 ms 9344 KB Output is correct
10 Correct 13 ms 9344 KB Output is correct
11 Correct 13 ms 9344 KB Output is correct
12 Correct 13 ms 9344 KB Output is correct
13 Correct 13 ms 9344 KB Output is correct
14 Correct 15 ms 9344 KB Output is correct
15 Correct 13 ms 9264 KB Output is correct
16 Correct 11 ms 8960 KB Output is correct
17 Correct 11 ms 8960 KB Output is correct
18 Correct 11 ms 8960 KB Output is correct
19 Correct 11 ms 8960 KB Output is correct
20 Correct 11 ms 8960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 12544 KB Output is correct
2 Correct 446 ms 12664 KB Output is correct
3 Correct 432 ms 12664 KB Output is correct
4 Correct 614 ms 12544 KB Output is correct
5 Correct 425 ms 12664 KB Output is correct
6 Correct 474 ms 12544 KB Output is correct
7 Correct 494 ms 12588 KB Output is correct
8 Correct 457 ms 12544 KB Output is correct
9 Correct 443 ms 12544 KB Output is correct
10 Correct 441 ms 12664 KB Output is correct
11 Correct 469 ms 12544 KB Output is correct
12 Correct 436 ms 12664 KB Output is correct
13 Correct 444 ms 12664 KB Output is correct
14 Correct 474 ms 12664 KB Output is correct
15 Correct 442 ms 12664 KB Output is correct
16 Correct 53 ms 9216 KB Output is correct
17 Correct 55 ms 9344 KB Output is correct
18 Correct 54 ms 9216 KB Output is correct
19 Correct 55 ms 9216 KB Output is correct
20 Correct 87 ms 9216 KB Output is correct
21 Correct 503 ms 12280 KB Output is correct
22 Correct 444 ms 12280 KB Output is correct
23 Correct 432 ms 12280 KB Output is correct
24 Correct 437 ms 12280 KB Output is correct
25 Correct 433 ms 12160 KB Output is correct
26 Correct 491 ms 12032 KB Output is correct
27 Correct 485 ms 12160 KB Output is correct
28 Correct 474 ms 12032 KB Output is correct
29 Correct 495 ms 12152 KB Output is correct
30 Correct 445 ms 12544 KB Output is correct
31 Correct 452 ms 12536 KB Output is correct
32 Correct 492 ms 12664 KB Output is correct
33 Correct 466 ms 12664 KB Output is correct
34 Correct 445 ms 12664 KB Output is correct
35 Correct 393 ms 12664 KB Output is correct
36 Correct 440 ms 12664 KB Output is correct
37 Correct 435 ms 12664 KB Output is correct
38 Correct 402 ms 12544 KB Output is correct
39 Correct 13 ms 9344 KB Output is correct
40 Correct 13 ms 9344 KB Output is correct
41 Correct 13 ms 9344 KB Output is correct
42 Correct 19 ms 9344 KB Output is correct
43 Correct 19 ms 9344 KB Output is correct
44 Correct 14 ms 9344 KB Output is correct
45 Correct 13 ms 9344 KB Output is correct
46 Correct 13 ms 9344 KB Output is correct
47 Correct 13 ms 9344 KB Output is correct
48 Correct 13 ms 9344 KB Output is correct
49 Correct 13 ms 9344 KB Output is correct
50 Correct 13 ms 9344 KB Output is correct
51 Correct 13 ms 9344 KB Output is correct
52 Correct 15 ms 9344 KB Output is correct
53 Correct 13 ms 9264 KB Output is correct
54 Correct 11 ms 8960 KB Output is correct
55 Correct 11 ms 8960 KB Output is correct
56 Correct 11 ms 8960 KB Output is correct
57 Correct 11 ms 8960 KB Output is correct
58 Correct 11 ms 8960 KB Output is correct
59 Correct 530 ms 12544 KB Output is correct
60 Correct 510 ms 12664 KB Output is correct
61 Correct 497 ms 12664 KB Output is correct
62 Correct 487 ms 12544 KB Output is correct
63 Correct 508 ms 12544 KB Output is correct
64 Correct 595 ms 12664 KB Output is correct
65 Correct 585 ms 12664 KB Output is correct
66 Correct 579 ms 12592 KB Output is correct
67 Correct 605 ms 12592 KB Output is correct
68 Correct 558 ms 12664 KB Output is correct
69 Correct 512 ms 12664 KB Output is correct
70 Correct 537 ms 12544 KB Output is correct
71 Correct 487 ms 12664 KB Output is correct
72 Correct 506 ms 12664 KB Output is correct
73 Correct 507 ms 12544 KB Output is correct
74 Correct 81 ms 9216 KB Output is correct
75 Correct 79 ms 9216 KB Output is correct
76 Correct 79 ms 9216 KB Output is correct
77 Correct 80 ms 9216 KB Output is correct
78 Correct 83 ms 9216 KB Output is correct