Submission #554277

# Submission time Handle Problem Language Result Execution time Memory
554277 2022-04-28T06:06:29 Z Koosha_mv Boat (APIO16_boat) C++14
100 / 100
745 ms 16060 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll

const int N=1005,mod=1e9+7;

int n,m,s[N],e[N],dp[N][N],inv[N],C[N][N];
vector<int> A;

ll pow(ll x,ll y,ll mod){return(!y?1:pow(x*x%mod,y/2,mod)*(y&1?x:1))%mod;}

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(time(NULL));
	inv[0]=1;
	f(i,1,N) inv[i]=pow(i,mod-2,mod);
	cin>>n;
	f(i,1,n+1){
		cin>>s[i]>>e[i];
		//s[i]=e[i]=rand()*rand()%mod;
		e[i]++;
		A.pb(s[i]);
		A.pb(e[i]);
	}
	sort(all(A));
	A.resize(unique(A.begin(),A.end())-A.begin());
	m=A.size();
	f(i,0,A.size()-1){
		C[i][0]=1;
		f(j,1,min(n,A[i+1]-A[i])+1){
			C[i][j]=C[i][j-1]*inv[j]%mod*(A[i+1]-A[i]+1-j)%mod;
		}
	}
	f(i,1,n+1){
		f(j,0,m-1) dp[j][0]=0;
		dp[0][0]=1;
		f(j,0,m-1){
			Add(dp[j+1][0],dp[j][0]);
			f(k,1,i+1) Add(dp[j+1][0],dp[j][k]*C[j][k]%mod);
		}
		f(j,0,m-1){
			if(e[i]<=A[j] || A[j+1]<=s[i]) continue ;
			f_(k,i,1){
				Add(dp[j][k],dp[j][k-1]);
			}
		}
	}
	int ans=0;
	f(i,0,m-1){
		f(j,1,n+1){
			Add(ans,dp[i][j]*C[i][j]%mod);
		}
	}
	cout<<ans;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:8:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   47 |  f(i,0,A.size()-1){
      |    ~~~~~~~~~~~~~~              
boat.cpp:47:2: note: in expansion of macro 'f'
   47 |  f(i,0,A.size()-1){
      |  ^
# Verdict Execution time Memory Grader output
1 Correct 619 ms 11232 KB Output is correct
2 Correct 627 ms 11328 KB Output is correct
3 Correct 620 ms 11584 KB Output is correct
4 Correct 611 ms 11340 KB Output is correct
5 Correct 603 ms 11340 KB Output is correct
6 Correct 602 ms 11416 KB Output is correct
7 Correct 621 ms 11516 KB Output is correct
8 Correct 623 ms 11160 KB Output is correct
9 Correct 627 ms 11384 KB Output is correct
10 Correct 623 ms 11224 KB Output is correct
11 Correct 607 ms 11336 KB Output is correct
12 Correct 592 ms 11188 KB Output is correct
13 Correct 618 ms 11216 KB Output is correct
14 Correct 616 ms 11224 KB Output is correct
15 Correct 608 ms 11328 KB Output is correct
16 Correct 102 ms 2328 KB Output is correct
17 Correct 111 ms 2484 KB Output is correct
18 Correct 104 ms 2428 KB Output is correct
19 Correct 110 ms 2508 KB Output is correct
20 Correct 107 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 11232 KB Output is correct
2 Correct 627 ms 11328 KB Output is correct
3 Correct 620 ms 11584 KB Output is correct
4 Correct 611 ms 11340 KB Output is correct
5 Correct 603 ms 11340 KB Output is correct
6 Correct 602 ms 11416 KB Output is correct
7 Correct 621 ms 11516 KB Output is correct
8 Correct 623 ms 11160 KB Output is correct
9 Correct 627 ms 11384 KB Output is correct
10 Correct 623 ms 11224 KB Output is correct
11 Correct 607 ms 11336 KB Output is correct
12 Correct 592 ms 11188 KB Output is correct
13 Correct 618 ms 11216 KB Output is correct
14 Correct 616 ms 11224 KB Output is correct
15 Correct 608 ms 11328 KB Output is correct
16 Correct 102 ms 2328 KB Output is correct
17 Correct 111 ms 2484 KB Output is correct
18 Correct 104 ms 2428 KB Output is correct
19 Correct 110 ms 2508 KB Output is correct
20 Correct 107 ms 2584 KB Output is correct
21 Correct 606 ms 11340 KB Output is correct
22 Correct 607 ms 11412 KB Output is correct
23 Correct 591 ms 11292 KB Output is correct
24 Correct 586 ms 11024 KB Output is correct
25 Correct 605 ms 11044 KB Output is correct
26 Correct 616 ms 10432 KB Output is correct
27 Correct 617 ms 10828 KB Output is correct
28 Correct 599 ms 10620 KB Output is correct
29 Correct 596 ms 10528 KB Output is correct
30 Correct 597 ms 12252 KB Output is correct
31 Correct 587 ms 12204 KB Output is correct
32 Correct 594 ms 12192 KB Output is correct
33 Correct 595 ms 12124 KB Output is correct
34 Correct 590 ms 11980 KB Output is correct
35 Correct 589 ms 12284 KB Output is correct
36 Correct 590 ms 12368 KB Output is correct
37 Correct 593 ms 12364 KB Output is correct
38 Correct 607 ms 12404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2260 KB Output is correct
2 Correct 8 ms 2268 KB Output is correct
3 Correct 7 ms 2132 KB Output is correct
4 Correct 7 ms 2208 KB Output is correct
5 Correct 7 ms 2132 KB Output is correct
6 Correct 7 ms 2184 KB Output is correct
7 Correct 8 ms 2264 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 7 ms 2260 KB Output is correct
10 Correct 8 ms 2216 KB Output is correct
11 Correct 7 ms 2248 KB Output is correct
12 Correct 7 ms 2136 KB Output is correct
13 Correct 7 ms 2132 KB Output is correct
14 Correct 7 ms 2132 KB Output is correct
15 Correct 9 ms 2140 KB Output is correct
16 Correct 5 ms 1364 KB Output is correct
17 Correct 5 ms 1400 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
19 Correct 4 ms 1364 KB Output is correct
20 Correct 5 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 11232 KB Output is correct
2 Correct 627 ms 11328 KB Output is correct
3 Correct 620 ms 11584 KB Output is correct
4 Correct 611 ms 11340 KB Output is correct
5 Correct 603 ms 11340 KB Output is correct
6 Correct 602 ms 11416 KB Output is correct
7 Correct 621 ms 11516 KB Output is correct
8 Correct 623 ms 11160 KB Output is correct
9 Correct 627 ms 11384 KB Output is correct
10 Correct 623 ms 11224 KB Output is correct
11 Correct 607 ms 11336 KB Output is correct
12 Correct 592 ms 11188 KB Output is correct
13 Correct 618 ms 11216 KB Output is correct
14 Correct 616 ms 11224 KB Output is correct
15 Correct 608 ms 11328 KB Output is correct
16 Correct 102 ms 2328 KB Output is correct
17 Correct 111 ms 2484 KB Output is correct
18 Correct 104 ms 2428 KB Output is correct
19 Correct 110 ms 2508 KB Output is correct
20 Correct 107 ms 2584 KB Output is correct
21 Correct 606 ms 11340 KB Output is correct
22 Correct 607 ms 11412 KB Output is correct
23 Correct 591 ms 11292 KB Output is correct
24 Correct 586 ms 11024 KB Output is correct
25 Correct 605 ms 11044 KB Output is correct
26 Correct 616 ms 10432 KB Output is correct
27 Correct 617 ms 10828 KB Output is correct
28 Correct 599 ms 10620 KB Output is correct
29 Correct 596 ms 10528 KB Output is correct
30 Correct 597 ms 12252 KB Output is correct
31 Correct 587 ms 12204 KB Output is correct
32 Correct 594 ms 12192 KB Output is correct
33 Correct 595 ms 12124 KB Output is correct
34 Correct 590 ms 11980 KB Output is correct
35 Correct 589 ms 12284 KB Output is correct
36 Correct 590 ms 12368 KB Output is correct
37 Correct 593 ms 12364 KB Output is correct
38 Correct 607 ms 12404 KB Output is correct
39 Correct 7 ms 2260 KB Output is correct
40 Correct 8 ms 2268 KB Output is correct
41 Correct 7 ms 2132 KB Output is correct
42 Correct 7 ms 2208 KB Output is correct
43 Correct 7 ms 2132 KB Output is correct
44 Correct 7 ms 2184 KB Output is correct
45 Correct 8 ms 2264 KB Output is correct
46 Correct 7 ms 2260 KB Output is correct
47 Correct 7 ms 2260 KB Output is correct
48 Correct 8 ms 2216 KB Output is correct
49 Correct 7 ms 2248 KB Output is correct
50 Correct 7 ms 2136 KB Output is correct
51 Correct 7 ms 2132 KB Output is correct
52 Correct 7 ms 2132 KB Output is correct
53 Correct 9 ms 2140 KB Output is correct
54 Correct 5 ms 1364 KB Output is correct
55 Correct 5 ms 1400 KB Output is correct
56 Correct 5 ms 1364 KB Output is correct
57 Correct 4 ms 1364 KB Output is correct
58 Correct 5 ms 1364 KB Output is correct
59 Correct 732 ms 16060 KB Output is correct
60 Correct 697 ms 16020 KB Output is correct
61 Correct 697 ms 15948 KB Output is correct
62 Correct 703 ms 16028 KB Output is correct
63 Correct 710 ms 15920 KB Output is correct
64 Correct 742 ms 15692 KB Output is correct
65 Correct 745 ms 15520 KB Output is correct
66 Correct 739 ms 15864 KB Output is correct
67 Correct 718 ms 15636 KB Output is correct
68 Correct 720 ms 15868 KB Output is correct
69 Correct 677 ms 15384 KB Output is correct
70 Correct 684 ms 15880 KB Output is correct
71 Correct 684 ms 15320 KB Output is correct
72 Correct 672 ms 15536 KB Output is correct
73 Correct 687 ms 15572 KB Output is correct
74 Correct 118 ms 2824 KB Output is correct
75 Correct 120 ms 2904 KB Output is correct
76 Correct 115 ms 2852 KB Output is correct
77 Correct 120 ms 2904 KB Output is correct
78 Correct 117 ms 2884 KB Output is correct