# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
209893 |
2020-03-15T21:45:29 Z |
AQT |
Boat (APIO16_boat) |
C++14 |
|
1088 ms |
10252 KB |
#include <bits/stdc++.h>
using namespace std;
int N;
const long long MOD = 1e9+7;
long long cst[505][1005];
long long dp[505][1005];
long long choose[505][505];
long long temp[505];
int lft[505], rht[505];
vector<int> cmp;
long long add(long long a, long long b){
return (a+b)%MOD;
}
long long mult(long long a, long long b){
return (a*b)%MOD;
}
long long qikpow(long long b, long long e){
if(!e){
return 1;
}
long long ret = qikpow(b, e>>1);
ret = mult(ret, ret);
if(e&1){
ret = mult(ret, b);
}
return ret;
}
long long divd(long long a, long long b){
return mult(a, qikpow(b, MOD-2));
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
//cmp.push_back(0);
for(int i= 1; i<=N; i++){
cin >> lft[i] >> rht[i];
cmp.push_back(lft[i]);
cmp.push_back(rht[i]+1);
}
sort(cmp.begin(), cmp.end());
cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
const int K = cmp.size()-1;
for(int i = 1; i<=N; i++){
lft[i] = lower_bound(cmp.begin(), cmp.end(), lft[i]) - cmp.begin();
rht[i] = lower_bound(cmp.begin(), cmp.end(), rht[i]+1) - cmp.begin();
}
choose[0][0] = 1;
for(int i = 0; i<=N; i++){
choose[i][0] = 1;
for(int k = 1; k<=N; k++){
choose[i][k] = add(choose[i-1][k], choose[i-1][k-1]);
}
}
temp[0] = 1;
for(int k = 1; k<=K; k++){
for(int n = 1; n<=N; n++){
if(n > cmp[k]-cmp[k-1]){
temp[n] = 0;
}
else{
temp[n] = mult(temp[n-1], cmp[k]-cmp[k-1]-n+1);
temp[n] = divd(temp[n], n);
}
}
for(int n = 1; n<=N; n++){
for(int a = 1; a<=n; a++){
//cout << temp[a] << " " << choose[n-1][a-1] << "\n";
cst[n][k] = add(cst[n][k], mult(choose[n-1][a-1], temp[a]));
}
//cout << n << " " << k << " " << cst[n][k] << "\n";
}
}
for(int k = 0; k<=K; k++){
dp[0][k] = 1;
}
for(int i = 1; i<=N; i++){
for(int k = 1; k<=K; k++){
dp[i][k] = dp[i][k-1];
if(rht[i] >= k && lft[i] < k){
int cnt = 0;
for(int j = i; j; j--){
if(rht[j] >= k && lft[j] < k){
cnt++;
}
dp[i][k] = add(dp[i][k], mult(dp[j-1][k-1], cst[cnt][k]));
}
}
}
}
long long ans = 0;
for(int i = 1; i<=N; i++){
//cout << dp[i][K] << " ";
ans = add(ans, dp[i][K]);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
676 ms |
10232 KB |
Output is correct |
2 |
Correct |
672 ms |
10232 KB |
Output is correct |
3 |
Correct |
672 ms |
10232 KB |
Output is correct |
4 |
Correct |
669 ms |
10232 KB |
Output is correct |
5 |
Correct |
669 ms |
10232 KB |
Output is correct |
6 |
Correct |
669 ms |
10232 KB |
Output is correct |
7 |
Correct |
673 ms |
10232 KB |
Output is correct |
8 |
Correct |
675 ms |
10232 KB |
Output is correct |
9 |
Correct |
664 ms |
10236 KB |
Output is correct |
10 |
Correct |
665 ms |
10232 KB |
Output is correct |
11 |
Correct |
674 ms |
10232 KB |
Output is correct |
12 |
Correct |
673 ms |
10232 KB |
Output is correct |
13 |
Correct |
670 ms |
10232 KB |
Output is correct |
14 |
Correct |
678 ms |
10232 KB |
Output is correct |
15 |
Correct |
672 ms |
10232 KB |
Output is correct |
16 |
Correct |
128 ms |
7800 KB |
Output is correct |
17 |
Correct |
138 ms |
7800 KB |
Output is correct |
18 |
Correct |
133 ms |
7800 KB |
Output is correct |
19 |
Correct |
141 ms |
7800 KB |
Output is correct |
20 |
Correct |
134 ms |
7800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
676 ms |
10232 KB |
Output is correct |
2 |
Correct |
672 ms |
10232 KB |
Output is correct |
3 |
Correct |
672 ms |
10232 KB |
Output is correct |
4 |
Correct |
669 ms |
10232 KB |
Output is correct |
5 |
Correct |
669 ms |
10232 KB |
Output is correct |
6 |
Correct |
669 ms |
10232 KB |
Output is correct |
7 |
Correct |
673 ms |
10232 KB |
Output is correct |
8 |
Correct |
675 ms |
10232 KB |
Output is correct |
9 |
Correct |
664 ms |
10236 KB |
Output is correct |
10 |
Correct |
665 ms |
10232 KB |
Output is correct |
11 |
Correct |
674 ms |
10232 KB |
Output is correct |
12 |
Correct |
673 ms |
10232 KB |
Output is correct |
13 |
Correct |
670 ms |
10232 KB |
Output is correct |
14 |
Correct |
678 ms |
10232 KB |
Output is correct |
15 |
Correct |
672 ms |
10232 KB |
Output is correct |
16 |
Correct |
128 ms |
7800 KB |
Output is correct |
17 |
Correct |
138 ms |
7800 KB |
Output is correct |
18 |
Correct |
133 ms |
7800 KB |
Output is correct |
19 |
Correct |
141 ms |
7800 KB |
Output is correct |
20 |
Correct |
134 ms |
7800 KB |
Output is correct |
21 |
Correct |
783 ms |
10232 KB |
Output is correct |
22 |
Correct |
785 ms |
10232 KB |
Output is correct |
23 |
Correct |
761 ms |
10232 KB |
Output is correct |
24 |
Correct |
793 ms |
10232 KB |
Output is correct |
25 |
Correct |
791 ms |
10232 KB |
Output is correct |
26 |
Correct |
853 ms |
10232 KB |
Output is correct |
27 |
Correct |
861 ms |
10232 KB |
Output is correct |
28 |
Correct |
892 ms |
10252 KB |
Output is correct |
29 |
Correct |
816 ms |
10208 KB |
Output is correct |
30 |
Correct |
667 ms |
10200 KB |
Output is correct |
31 |
Correct |
664 ms |
10168 KB |
Output is correct |
32 |
Correct |
664 ms |
10232 KB |
Output is correct |
33 |
Correct |
661 ms |
10232 KB |
Output is correct |
34 |
Correct |
660 ms |
10252 KB |
Output is correct |
35 |
Correct |
658 ms |
10232 KB |
Output is correct |
36 |
Correct |
662 ms |
10232 KB |
Output is correct |
37 |
Correct |
662 ms |
10232 KB |
Output is correct |
38 |
Correct |
663 ms |
10232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1912 KB |
Output is correct |
2 |
Correct |
17 ms |
1912 KB |
Output is correct |
3 |
Correct |
18 ms |
1912 KB |
Output is correct |
4 |
Correct |
18 ms |
1912 KB |
Output is correct |
5 |
Correct |
18 ms |
1912 KB |
Output is correct |
6 |
Correct |
18 ms |
1916 KB |
Output is correct |
7 |
Correct |
18 ms |
1912 KB |
Output is correct |
8 |
Correct |
19 ms |
1912 KB |
Output is correct |
9 |
Correct |
18 ms |
1912 KB |
Output is correct |
10 |
Correct |
19 ms |
1912 KB |
Output is correct |
11 |
Correct |
18 ms |
1912 KB |
Output is correct |
12 |
Correct |
17 ms |
1912 KB |
Output is correct |
13 |
Correct |
17 ms |
1912 KB |
Output is correct |
14 |
Correct |
17 ms |
1912 KB |
Output is correct |
15 |
Correct |
17 ms |
1912 KB |
Output is correct |
16 |
Correct |
12 ms |
1724 KB |
Output is correct |
17 |
Correct |
12 ms |
1784 KB |
Output is correct |
18 |
Correct |
14 ms |
1784 KB |
Output is correct |
19 |
Correct |
12 ms |
1784 KB |
Output is correct |
20 |
Correct |
12 ms |
1784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
676 ms |
10232 KB |
Output is correct |
2 |
Correct |
672 ms |
10232 KB |
Output is correct |
3 |
Correct |
672 ms |
10232 KB |
Output is correct |
4 |
Correct |
669 ms |
10232 KB |
Output is correct |
5 |
Correct |
669 ms |
10232 KB |
Output is correct |
6 |
Correct |
669 ms |
10232 KB |
Output is correct |
7 |
Correct |
673 ms |
10232 KB |
Output is correct |
8 |
Correct |
675 ms |
10232 KB |
Output is correct |
9 |
Correct |
664 ms |
10236 KB |
Output is correct |
10 |
Correct |
665 ms |
10232 KB |
Output is correct |
11 |
Correct |
674 ms |
10232 KB |
Output is correct |
12 |
Correct |
673 ms |
10232 KB |
Output is correct |
13 |
Correct |
670 ms |
10232 KB |
Output is correct |
14 |
Correct |
678 ms |
10232 KB |
Output is correct |
15 |
Correct |
672 ms |
10232 KB |
Output is correct |
16 |
Correct |
128 ms |
7800 KB |
Output is correct |
17 |
Correct |
138 ms |
7800 KB |
Output is correct |
18 |
Correct |
133 ms |
7800 KB |
Output is correct |
19 |
Correct |
141 ms |
7800 KB |
Output is correct |
20 |
Correct |
134 ms |
7800 KB |
Output is correct |
21 |
Correct |
783 ms |
10232 KB |
Output is correct |
22 |
Correct |
785 ms |
10232 KB |
Output is correct |
23 |
Correct |
761 ms |
10232 KB |
Output is correct |
24 |
Correct |
793 ms |
10232 KB |
Output is correct |
25 |
Correct |
791 ms |
10232 KB |
Output is correct |
26 |
Correct |
853 ms |
10232 KB |
Output is correct |
27 |
Correct |
861 ms |
10232 KB |
Output is correct |
28 |
Correct |
892 ms |
10252 KB |
Output is correct |
29 |
Correct |
816 ms |
10208 KB |
Output is correct |
30 |
Correct |
667 ms |
10200 KB |
Output is correct |
31 |
Correct |
664 ms |
10168 KB |
Output is correct |
32 |
Correct |
664 ms |
10232 KB |
Output is correct |
33 |
Correct |
661 ms |
10232 KB |
Output is correct |
34 |
Correct |
660 ms |
10252 KB |
Output is correct |
35 |
Correct |
658 ms |
10232 KB |
Output is correct |
36 |
Correct |
662 ms |
10232 KB |
Output is correct |
37 |
Correct |
662 ms |
10232 KB |
Output is correct |
38 |
Correct |
663 ms |
10232 KB |
Output is correct |
39 |
Correct |
17 ms |
1912 KB |
Output is correct |
40 |
Correct |
17 ms |
1912 KB |
Output is correct |
41 |
Correct |
18 ms |
1912 KB |
Output is correct |
42 |
Correct |
18 ms |
1912 KB |
Output is correct |
43 |
Correct |
18 ms |
1912 KB |
Output is correct |
44 |
Correct |
18 ms |
1916 KB |
Output is correct |
45 |
Correct |
18 ms |
1912 KB |
Output is correct |
46 |
Correct |
19 ms |
1912 KB |
Output is correct |
47 |
Correct |
18 ms |
1912 KB |
Output is correct |
48 |
Correct |
19 ms |
1912 KB |
Output is correct |
49 |
Correct |
18 ms |
1912 KB |
Output is correct |
50 |
Correct |
17 ms |
1912 KB |
Output is correct |
51 |
Correct |
17 ms |
1912 KB |
Output is correct |
52 |
Correct |
17 ms |
1912 KB |
Output is correct |
53 |
Correct |
17 ms |
1912 KB |
Output is correct |
54 |
Correct |
12 ms |
1724 KB |
Output is correct |
55 |
Correct |
12 ms |
1784 KB |
Output is correct |
56 |
Correct |
14 ms |
1784 KB |
Output is correct |
57 |
Correct |
12 ms |
1784 KB |
Output is correct |
58 |
Correct |
12 ms |
1784 KB |
Output is correct |
59 |
Correct |
1002 ms |
10236 KB |
Output is correct |
60 |
Correct |
998 ms |
10232 KB |
Output is correct |
61 |
Correct |
959 ms |
10172 KB |
Output is correct |
62 |
Correct |
977 ms |
10232 KB |
Output is correct |
63 |
Correct |
979 ms |
10176 KB |
Output is correct |
64 |
Correct |
1088 ms |
10232 KB |
Output is correct |
65 |
Correct |
1076 ms |
10232 KB |
Output is correct |
66 |
Correct |
1075 ms |
10232 KB |
Output is correct |
67 |
Correct |
1073 ms |
10232 KB |
Output is correct |
68 |
Correct |
1079 ms |
10232 KB |
Output is correct |
69 |
Correct |
935 ms |
10232 KB |
Output is correct |
70 |
Correct |
914 ms |
10232 KB |
Output is correct |
71 |
Correct |
906 ms |
10232 KB |
Output is correct |
72 |
Correct |
912 ms |
10232 KB |
Output is correct |
73 |
Correct |
932 ms |
10232 KB |
Output is correct |
74 |
Correct |
182 ms |
7800 KB |
Output is correct |
75 |
Correct |
181 ms |
7800 KB |
Output is correct |
76 |
Correct |
183 ms |
7676 KB |
Output is correct |
77 |
Correct |
182 ms |
7800 KB |
Output is correct |
78 |
Correct |
180 ms |
7800 KB |
Output is correct |