Submission #764509

# Submission time Handle Problem Language Result Execution time Memory
764509 2023-06-23T13:46:15 Z Ahmed57 Boat (APIO16_boat) C++17
100 / 100
1453 ms 8308 KB
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long fast(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a;
    long long h = fast(a,b/2);h*=h;h%=mod;
    if(b%2==0)return h;
    else return (h*a)%mod;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    long long rev[n+1];
    for(int i = 0;i<=n;i++){
        rev[i] = fast(i,mod-2);
    }
    vector<pair<long long,long long>> v;
    vector<long long> ans;
    for(int i = 0;i<n;i++){
        long long x,y;
        cin>>x>>y;
        v.push_back({x,y});
        ans.push_back(x-1);
        ans.push_back(y);
    }
    ans.push_back(0);
    sort(ans.begin(),ans.end());
    ans.resize(unique(ans.begin(),ans.end())-ans.begin());
    long long fin = 0;
    long long dp[2001][501];
    memset(dp,0,sizeof dp);
    long long ps[2001];
    dp[0][0] = 1;
    long long sz = ans.size()+1;
    for(int i = 0;i<=sz+8;i++){
        ps[i] = 1;
    }
    for(int i=1;i<=n;i++){
		int l=lower_bound(ans.begin(),ans.end(),v[i-1].first)-ans.begin();
		int r=lower_bound(ans.begin(),ans.end(),v[i-1].second)-ans.begin();
		for(int j=l;j<=r;j++){
			long long cnt=ans[j]-ans[j-1];
			for(long long h=n;h>=2;h--){
				dp[j][h]=(dp[j][h]+dp[j][h-1]*(cnt-(h-1))%mod*rev[h])%mod;
			}
			dp[j][1]=(dp[j][1]+ps[j-1]*cnt)%mod;
		}
		ps[0]=dp[0][0];
		for(int i=1;i<=sz+9;i++){
			ps[i]=ps[i-1];
			for(int h=0;h<=n;h++){
				ps[i]+=dp[i][h];
			}
			ps[i]%=mod;
		}
	}
    cout<<(ps[sz+8]+(mod-1))%mod<<endl;
}
/*
1 4
3 4
{1,3},{1,4},{2,3},{2,4},{3,4}
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:31:15: warning: unused variable 'fin' [-Wunused-variable]
   31 |     long long fin = 0;
      |               ^~~
# Verdict Execution time Memory Grader output
1 Correct 117 ms 8148 KB Output is correct
2 Correct 101 ms 8184 KB Output is correct
3 Correct 119 ms 8200 KB Output is correct
4 Correct 107 ms 8148 KB Output is correct
5 Correct 114 ms 8188 KB Output is correct
6 Correct 116 ms 8188 KB Output is correct
7 Correct 97 ms 8148 KB Output is correct
8 Correct 104 ms 8188 KB Output is correct
9 Correct 100 ms 8192 KB Output is correct
10 Correct 121 ms 8188 KB Output is correct
11 Correct 115 ms 8148 KB Output is correct
12 Correct 116 ms 8188 KB Output is correct
13 Correct 104 ms 8276 KB Output is correct
14 Correct 100 ms 8148 KB Output is correct
15 Correct 118 ms 8188 KB Output is correct
16 Correct 26 ms 8148 KB Output is correct
17 Correct 28 ms 8204 KB Output is correct
18 Correct 27 ms 8212 KB Output is correct
19 Correct 29 ms 8208 KB Output is correct
20 Correct 27 ms 8208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 8148 KB Output is correct
2 Correct 101 ms 8184 KB Output is correct
3 Correct 119 ms 8200 KB Output is correct
4 Correct 107 ms 8148 KB Output is correct
5 Correct 114 ms 8188 KB Output is correct
6 Correct 116 ms 8188 KB Output is correct
7 Correct 97 ms 8148 KB Output is correct
8 Correct 104 ms 8188 KB Output is correct
9 Correct 100 ms 8192 KB Output is correct
10 Correct 121 ms 8188 KB Output is correct
11 Correct 115 ms 8148 KB Output is correct
12 Correct 116 ms 8188 KB Output is correct
13 Correct 104 ms 8276 KB Output is correct
14 Correct 100 ms 8148 KB Output is correct
15 Correct 118 ms 8188 KB Output is correct
16 Correct 26 ms 8148 KB Output is correct
17 Correct 28 ms 8204 KB Output is correct
18 Correct 27 ms 8212 KB Output is correct
19 Correct 29 ms 8208 KB Output is correct
20 Correct 27 ms 8208 KB Output is correct
21 Correct 769 ms 8184 KB Output is correct
22 Correct 760 ms 8200 KB Output is correct
23 Correct 714 ms 8192 KB Output is correct
24 Correct 746 ms 8200 KB Output is correct
25 Correct 764 ms 8196 KB Output is correct
26 Correct 1026 ms 8148 KB Output is correct
27 Correct 1045 ms 8208 KB Output is correct
28 Correct 1032 ms 8192 KB Output is correct
29 Correct 1022 ms 8196 KB Output is correct
30 Correct 117 ms 8176 KB Output is correct
31 Correct 121 ms 8148 KB Output is correct
32 Correct 119 ms 8148 KB Output is correct
33 Correct 110 ms 8200 KB Output is correct
34 Correct 117 ms 8200 KB Output is correct
35 Correct 118 ms 8200 KB Output is correct
36 Correct 107 ms 8200 KB Output is correct
37 Correct 115 ms 8200 KB Output is correct
38 Correct 108 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8148 KB Output is correct
2 Correct 10 ms 8148 KB Output is correct
3 Correct 11 ms 8148 KB Output is correct
4 Correct 12 ms 8188 KB Output is correct
5 Correct 12 ms 8176 KB Output is correct
6 Correct 16 ms 8176 KB Output is correct
7 Correct 15 ms 8148 KB Output is correct
8 Correct 15 ms 8148 KB Output is correct
9 Correct 15 ms 8188 KB Output is correct
10 Correct 15 ms 8160 KB Output is correct
11 Correct 12 ms 8148 KB Output is correct
12 Correct 10 ms 8148 KB Output is correct
13 Correct 11 ms 8188 KB Output is correct
14 Correct 11 ms 8108 KB Output is correct
15 Correct 12 ms 8148 KB Output is correct
16 Correct 8 ms 8148 KB Output is correct
17 Correct 8 ms 8180 KB Output is correct
18 Correct 9 ms 8280 KB Output is correct
19 Correct 8 ms 8176 KB Output is correct
20 Correct 9 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 8148 KB Output is correct
2 Correct 101 ms 8184 KB Output is correct
3 Correct 119 ms 8200 KB Output is correct
4 Correct 107 ms 8148 KB Output is correct
5 Correct 114 ms 8188 KB Output is correct
6 Correct 116 ms 8188 KB Output is correct
7 Correct 97 ms 8148 KB Output is correct
8 Correct 104 ms 8188 KB Output is correct
9 Correct 100 ms 8192 KB Output is correct
10 Correct 121 ms 8188 KB Output is correct
11 Correct 115 ms 8148 KB Output is correct
12 Correct 116 ms 8188 KB Output is correct
13 Correct 104 ms 8276 KB Output is correct
14 Correct 100 ms 8148 KB Output is correct
15 Correct 118 ms 8188 KB Output is correct
16 Correct 26 ms 8148 KB Output is correct
17 Correct 28 ms 8204 KB Output is correct
18 Correct 27 ms 8212 KB Output is correct
19 Correct 29 ms 8208 KB Output is correct
20 Correct 27 ms 8208 KB Output is correct
21 Correct 769 ms 8184 KB Output is correct
22 Correct 760 ms 8200 KB Output is correct
23 Correct 714 ms 8192 KB Output is correct
24 Correct 746 ms 8200 KB Output is correct
25 Correct 764 ms 8196 KB Output is correct
26 Correct 1026 ms 8148 KB Output is correct
27 Correct 1045 ms 8208 KB Output is correct
28 Correct 1032 ms 8192 KB Output is correct
29 Correct 1022 ms 8196 KB Output is correct
30 Correct 117 ms 8176 KB Output is correct
31 Correct 121 ms 8148 KB Output is correct
32 Correct 119 ms 8148 KB Output is correct
33 Correct 110 ms 8200 KB Output is correct
34 Correct 117 ms 8200 KB Output is correct
35 Correct 118 ms 8200 KB Output is correct
36 Correct 107 ms 8200 KB Output is correct
37 Correct 115 ms 8200 KB Output is correct
38 Correct 108 ms 8148 KB Output is correct
39 Correct 12 ms 8148 KB Output is correct
40 Correct 10 ms 8148 KB Output is correct
41 Correct 11 ms 8148 KB Output is correct
42 Correct 12 ms 8188 KB Output is correct
43 Correct 12 ms 8176 KB Output is correct
44 Correct 16 ms 8176 KB Output is correct
45 Correct 15 ms 8148 KB Output is correct
46 Correct 15 ms 8148 KB Output is correct
47 Correct 15 ms 8188 KB Output is correct
48 Correct 15 ms 8160 KB Output is correct
49 Correct 12 ms 8148 KB Output is correct
50 Correct 10 ms 8148 KB Output is correct
51 Correct 11 ms 8188 KB Output is correct
52 Correct 11 ms 8108 KB Output is correct
53 Correct 12 ms 8148 KB Output is correct
54 Correct 8 ms 8148 KB Output is correct
55 Correct 8 ms 8180 KB Output is correct
56 Correct 9 ms 8280 KB Output is correct
57 Correct 8 ms 8176 KB Output is correct
58 Correct 9 ms 8148 KB Output is correct
59 Correct 964 ms 8196 KB Output is correct
60 Correct 907 ms 8208 KB Output is correct
61 Correct 877 ms 8212 KB Output is correct
62 Correct 963 ms 8196 KB Output is correct
63 Correct 936 ms 8308 KB Output is correct
64 Correct 1453 ms 8200 KB Output is correct
65 Correct 1445 ms 8196 KB Output is correct
66 Correct 1451 ms 8148 KB Output is correct
67 Correct 1448 ms 8196 KB Output is correct
68 Correct 1445 ms 8268 KB Output is correct
69 Correct 878 ms 8148 KB Output is correct
70 Correct 893 ms 8268 KB Output is correct
71 Correct 889 ms 8200 KB Output is correct
72 Correct 914 ms 8196 KB Output is correct
73 Correct 913 ms 8148 KB Output is correct
74 Correct 176 ms 8148 KB Output is correct
75 Correct 175 ms 8268 KB Output is correct
76 Correct 178 ms 8148 KB Output is correct
77 Correct 178 ms 8200 KB Output is correct
78 Correct 175 ms 8148 KB Output is correct