답안 #716723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716723 2023-03-30T23:38:42 Z snpmrnhlol Boat (APIO16_boat) C++11
100 / 100
942 ms 4660 KB
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int segs[250001],dp[250001];
int length[1001];
int segl[1001];
int l[501],r[501];
int dp2[1001];
int inv[250001];
vector <int> v2[1001];
int p(int a,int b){
    int r = 1;
    while(b > 0){
        if(b%2 == 1)r = 1ll*r*a%mod;
        a = 1ll*a*a%mod;
        b/=2;
    }
    return r;
}
void precalc(){
    for(int i = 0;i <= 250000;i++){
        inv[i] = p(i,mod - 2);
    }
}
int main(){
    precalc();
    int n,i,cnt = 1,j,cnt2 = 0,ans = 0;
    cin>>n;
    for(i = 0;i < n;i++){
        cin>>l[i]>>r[i];
        segl[i*2] = l[i];
        segl[i*2+1] = r[i] + 1;
    }
    sort(segl,segl + 2*n);
    for(i = 1;i < 2*n;i++){
        if(segl[i] != segl[cnt - 1]){
            segl[cnt++] = segl[i];
        }
    }
    for(i = 0;i < n;i++){
        for(j = cnt - 1;j >= 0;j--){
            if(l[i] <= segl[j] && segl[j] <= r[i]){
                segs[cnt2++] = j;
                length[j] = segl[j + 1] - segl[j];
            }
        }
    }
    segs[cnt2++] = cnt;
    length[cnt] = 1;
    for(i = 0;i < cnt2;i++){
        dp[i] = 1;
        for(j = segs[i] - 1;j >= 0;j--){
            dp[i]+=dp2[j];
            dp[i]%=mod;
        }
        ///update dp2[segs[i]]
        dp2[segs[i]] = 0;
        v2[segs[i]].push_back(dp[i]);
        int prod = length[segs[i]];
        for(j = v2[segs[i]].size() - 1;j >= 0;j--){
            dp2[segs[i]] = (dp2[segs[i]] + 1ll*v2[segs[i]][j]*prod)%mod;
            prod = 1ll*prod*(length[segs[i]] + v2[segs[i]].size() - j)%mod;
            prod = 1ll*prod*inv[v2[segs[i]].size() - j + 1]%mod;
        }
    }
    ans = (dp[cnt2 - 1] + mod - 1)%mod;
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1216 KB Output is correct
2 Correct 36 ms 1240 KB Output is correct
3 Correct 35 ms 1296 KB Output is correct
4 Correct 36 ms 1256 KB Output is correct
5 Correct 39 ms 1308 KB Output is correct
6 Correct 37 ms 1224 KB Output is correct
7 Correct 38 ms 1316 KB Output is correct
8 Correct 37 ms 1252 KB Output is correct
9 Correct 37 ms 1228 KB Output is correct
10 Correct 37 ms 1320 KB Output is correct
11 Correct 35 ms 1236 KB Output is correct
12 Correct 36 ms 1268 KB Output is correct
13 Correct 37 ms 1300 KB Output is correct
14 Correct 40 ms 1236 KB Output is correct
15 Correct 36 ms 1236 KB Output is correct
16 Correct 36 ms 1216 KB Output is correct
17 Correct 37 ms 1244 KB Output is correct
18 Correct 36 ms 1236 KB Output is correct
19 Correct 37 ms 1228 KB Output is correct
20 Correct 36 ms 1268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1216 KB Output is correct
2 Correct 36 ms 1240 KB Output is correct
3 Correct 35 ms 1296 KB Output is correct
4 Correct 36 ms 1256 KB Output is correct
5 Correct 39 ms 1308 KB Output is correct
6 Correct 37 ms 1224 KB Output is correct
7 Correct 38 ms 1316 KB Output is correct
8 Correct 37 ms 1252 KB Output is correct
9 Correct 37 ms 1228 KB Output is correct
10 Correct 37 ms 1320 KB Output is correct
11 Correct 35 ms 1236 KB Output is correct
12 Correct 36 ms 1268 KB Output is correct
13 Correct 37 ms 1300 KB Output is correct
14 Correct 40 ms 1236 KB Output is correct
15 Correct 36 ms 1236 KB Output is correct
16 Correct 36 ms 1216 KB Output is correct
17 Correct 37 ms 1244 KB Output is correct
18 Correct 36 ms 1236 KB Output is correct
19 Correct 37 ms 1228 KB Output is correct
20 Correct 36 ms 1268 KB Output is correct
21 Correct 464 ms 3416 KB Output is correct
22 Correct 467 ms 3388 KB Output is correct
23 Correct 428 ms 3252 KB Output is correct
24 Correct 450 ms 3424 KB Output is correct
25 Correct 463 ms 3492 KB Output is correct
26 Correct 779 ms 4288 KB Output is correct
27 Correct 797 ms 4244 KB Output is correct
28 Correct 752 ms 4240 KB Output is correct
29 Correct 753 ms 4196 KB Output is correct
30 Correct 40 ms 1356 KB Output is correct
31 Correct 39 ms 1296 KB Output is correct
32 Correct 39 ms 1288 KB Output is correct
33 Correct 38 ms 1236 KB Output is correct
34 Correct 38 ms 1268 KB Output is correct
35 Correct 41 ms 1280 KB Output is correct
36 Correct 42 ms 1228 KB Output is correct
37 Correct 41 ms 1316 KB Output is correct
38 Correct 39 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 1372 KB Output is correct
2 Correct 38 ms 1448 KB Output is correct
3 Correct 37 ms 1364 KB Output is correct
4 Correct 40 ms 1380 KB Output is correct
5 Correct 39 ms 1368 KB Output is correct
6 Correct 42 ms 1412 KB Output is correct
7 Correct 43 ms 1380 KB Output is correct
8 Correct 41 ms 1344 KB Output is correct
9 Correct 42 ms 1352 KB Output is correct
10 Correct 43 ms 1468 KB Output is correct
11 Correct 42 ms 1412 KB Output is correct
12 Correct 42 ms 1288 KB Output is correct
13 Correct 43 ms 1356 KB Output is correct
14 Correct 39 ms 1304 KB Output is correct
15 Correct 40 ms 1312 KB Output is correct
16 Correct 37 ms 1332 KB Output is correct
17 Correct 38 ms 1356 KB Output is correct
18 Correct 37 ms 1352 KB Output is correct
19 Correct 39 ms 1336 KB Output is correct
20 Correct 39 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1216 KB Output is correct
2 Correct 36 ms 1240 KB Output is correct
3 Correct 35 ms 1296 KB Output is correct
4 Correct 36 ms 1256 KB Output is correct
5 Correct 39 ms 1308 KB Output is correct
6 Correct 37 ms 1224 KB Output is correct
7 Correct 38 ms 1316 KB Output is correct
8 Correct 37 ms 1252 KB Output is correct
9 Correct 37 ms 1228 KB Output is correct
10 Correct 37 ms 1320 KB Output is correct
11 Correct 35 ms 1236 KB Output is correct
12 Correct 36 ms 1268 KB Output is correct
13 Correct 37 ms 1300 KB Output is correct
14 Correct 40 ms 1236 KB Output is correct
15 Correct 36 ms 1236 KB Output is correct
16 Correct 36 ms 1216 KB Output is correct
17 Correct 37 ms 1244 KB Output is correct
18 Correct 36 ms 1236 KB Output is correct
19 Correct 37 ms 1228 KB Output is correct
20 Correct 36 ms 1268 KB Output is correct
21 Correct 464 ms 3416 KB Output is correct
22 Correct 467 ms 3388 KB Output is correct
23 Correct 428 ms 3252 KB Output is correct
24 Correct 450 ms 3424 KB Output is correct
25 Correct 463 ms 3492 KB Output is correct
26 Correct 779 ms 4288 KB Output is correct
27 Correct 797 ms 4244 KB Output is correct
28 Correct 752 ms 4240 KB Output is correct
29 Correct 753 ms 4196 KB Output is correct
30 Correct 40 ms 1356 KB Output is correct
31 Correct 39 ms 1296 KB Output is correct
32 Correct 39 ms 1288 KB Output is correct
33 Correct 38 ms 1236 KB Output is correct
34 Correct 38 ms 1268 KB Output is correct
35 Correct 41 ms 1280 KB Output is correct
36 Correct 42 ms 1228 KB Output is correct
37 Correct 41 ms 1316 KB Output is correct
38 Correct 39 ms 1228 KB Output is correct
39 Correct 39 ms 1372 KB Output is correct
40 Correct 38 ms 1448 KB Output is correct
41 Correct 37 ms 1364 KB Output is correct
42 Correct 40 ms 1380 KB Output is correct
43 Correct 39 ms 1368 KB Output is correct
44 Correct 42 ms 1412 KB Output is correct
45 Correct 43 ms 1380 KB Output is correct
46 Correct 41 ms 1344 KB Output is correct
47 Correct 42 ms 1352 KB Output is correct
48 Correct 43 ms 1468 KB Output is correct
49 Correct 42 ms 1412 KB Output is correct
50 Correct 42 ms 1288 KB Output is correct
51 Correct 43 ms 1356 KB Output is correct
52 Correct 39 ms 1304 KB Output is correct
53 Correct 40 ms 1312 KB Output is correct
54 Correct 37 ms 1332 KB Output is correct
55 Correct 38 ms 1356 KB Output is correct
56 Correct 37 ms 1352 KB Output is correct
57 Correct 39 ms 1336 KB Output is correct
58 Correct 39 ms 1356 KB Output is correct
59 Correct 528 ms 3576 KB Output is correct
60 Correct 497 ms 3452 KB Output is correct
61 Correct 472 ms 3404 KB Output is correct
62 Correct 553 ms 3820 KB Output is correct
63 Correct 536 ms 3624 KB Output is correct
64 Correct 942 ms 4632 KB Output is correct
65 Correct 920 ms 4616 KB Output is correct
66 Correct 936 ms 4660 KB Output is correct
67 Correct 937 ms 4548 KB Output is correct
68 Correct 926 ms 4616 KB Output is correct
69 Correct 485 ms 3388 KB Output is correct
70 Correct 501 ms 3412 KB Output is correct
71 Correct 473 ms 3356 KB Output is correct
72 Correct 525 ms 3396 KB Output is correct
73 Correct 494 ms 3508 KB Output is correct
74 Correct 85 ms 1656 KB Output is correct
75 Correct 81 ms 1728 KB Output is correct
76 Correct 79 ms 1768 KB Output is correct
77 Correct 81 ms 1664 KB Output is correct
78 Correct 82 ms 1748 KB Output is correct