Submission #632102

# Submission time Handle Problem Language Result Execution time Memory
632102 2022-08-19T12:32:35 Z CSQ31 Boat (APIO16_boat) C++17
100 / 100
1145 ms 4300 KB
#pragma GCC optimize("Ofast") 
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (int)(1e9)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MOD = 1e9+7;
int dp1[1001][501],dp2[1001][501]; //boat,group,cnt
int a[501],b[501],fac[501];
int binpow(int n,int k){
	int res = 1;
	while(k){
		if(k&1)res = res*1LL*n%MOD;
		n = n*1LL*n%MOD;
		k/=2;
	}
	return res;
}
int main()
{
	owo
	int n;
	cin>>n;
	fac[1] = 1;
	for(int i=2;i<=n;i++)fac[i] = fac[i-1]*1LL*i%MOD;
	for(int i=1;i<=n;i++)fac[i] = binpow(fac[i],MOD-2);
	vector<int>c;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		c.pb(a[i]);
		c.pb(b[i]+1);
	}
	sort(all(c));
	c.resize(unique(all(c)) - c.begin());
	int m = sz(c),tot = 1;
	for(int i=0;i<n;i++){
		tot = 1;
		for(int j=0;j+1<m;j++){
			int s = c[j+1]-c[j];
			for(int k=1;k<=min(n,s);k++)dp2[j][k] = dp1[j][k];
			if(a[i] <= c[j] && c[j] <= b[i]){ 
				//add you in new group
				dp2[j][1] += tot * 1LL * s%MOD;
				if(dp2[j][1]>=MOD)dp2[j][1]-=MOD;
				//add you to existing group
					for(int k=2;k<=min(n,s);k++){
						dp2[j][k] += dp1[j][k-1] * 1LL * (s-k+1)%MOD;
						if(dp2[j][k]>=MOD)dp2[j][k]-=MOD;
					}
			}
			for(int k=1;k<=min(n,s);k++){//update tot
				tot+=dp1[j][k] * 1LL * fac[k]%MOD;
				if(tot>=MOD)tot-=MOD;
			}	
		}
		for(int j=0;j+1<m;j++){
			int s = c[j+1]-c[j];
			for(int k=1;k<=min(n,s);k++){
				dp1[j][k] = dp2[j][k];
				dp2[j][k] = 0;
			}
			
		}
	}
	int ans = 0;
	for(int i=0;i<m;i++){
		for(int j=1;j<=n;j++){
			ans+=dp1[i][j]*1LL*fac[j]%MOD;
			ans%=MOD;
		}
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 370 ms 4244 KB Output is correct
2 Correct 376 ms 4236 KB Output is correct
3 Correct 394 ms 4240 KB Output is correct
4 Correct 402 ms 4244 KB Output is correct
5 Correct 392 ms 4236 KB Output is correct
6 Correct 382 ms 4180 KB Output is correct
7 Correct 373 ms 4232 KB Output is correct
8 Correct 385 ms 4240 KB Output is correct
9 Correct 384 ms 4180 KB Output is correct
10 Correct 375 ms 4248 KB Output is correct
11 Correct 382 ms 4236 KB Output is correct
12 Correct 409 ms 4236 KB Output is correct
13 Correct 387 ms 4240 KB Output is correct
14 Correct 383 ms 4232 KB Output is correct
15 Correct 376 ms 4236 KB Output is correct
16 Correct 68 ms 1004 KB Output is correct
17 Correct 76 ms 1068 KB Output is correct
18 Correct 67 ms 1028 KB Output is correct
19 Correct 71 ms 1068 KB Output is correct
20 Correct 68 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 370 ms 4244 KB Output is correct
2 Correct 376 ms 4236 KB Output is correct
3 Correct 394 ms 4240 KB Output is correct
4 Correct 402 ms 4244 KB Output is correct
5 Correct 392 ms 4236 KB Output is correct
6 Correct 382 ms 4180 KB Output is correct
7 Correct 373 ms 4232 KB Output is correct
8 Correct 385 ms 4240 KB Output is correct
9 Correct 384 ms 4180 KB Output is correct
10 Correct 375 ms 4248 KB Output is correct
11 Correct 382 ms 4236 KB Output is correct
12 Correct 409 ms 4236 KB Output is correct
13 Correct 387 ms 4240 KB Output is correct
14 Correct 383 ms 4232 KB Output is correct
15 Correct 376 ms 4236 KB Output is correct
16 Correct 68 ms 1004 KB Output is correct
17 Correct 76 ms 1068 KB Output is correct
18 Correct 67 ms 1028 KB Output is correct
19 Correct 71 ms 1068 KB Output is correct
20 Correct 68 ms 1040 KB Output is correct
21 Correct 25 ms 3796 KB Output is correct
22 Correct 26 ms 3916 KB Output is correct
23 Correct 31 ms 3784 KB Output is correct
24 Correct 27 ms 3796 KB Output is correct
25 Correct 25 ms 3788 KB Output is correct
26 Correct 23 ms 3796 KB Output is correct
27 Correct 25 ms 3796 KB Output is correct
28 Correct 23 ms 3784 KB Output is correct
29 Correct 25 ms 3668 KB Output is correct
30 Correct 368 ms 4236 KB Output is correct
31 Correct 364 ms 4248 KB Output is correct
32 Correct 365 ms 4236 KB Output is correct
33 Correct 346 ms 4248 KB Output is correct
34 Correct 374 ms 4232 KB Output is correct
35 Correct 336 ms 4180 KB Output is correct
36 Correct 359 ms 4240 KB Output is correct
37 Correct 350 ms 4236 KB Output is correct
38 Correct 356 ms 4228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1108 KB Output is correct
2 Correct 9 ms 1152 KB Output is correct
3 Correct 8 ms 1108 KB Output is correct
4 Correct 9 ms 1116 KB Output is correct
5 Correct 11 ms 1108 KB Output is correct
6 Correct 9 ms 1116 KB Output is correct
7 Correct 10 ms 1096 KB Output is correct
8 Correct 10 ms 1096 KB Output is correct
9 Correct 10 ms 1108 KB Output is correct
10 Correct 13 ms 1108 KB Output is correct
11 Correct 10 ms 1096 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 9 ms 1108 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 9 ms 1124 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 4 ms 736 KB Output is correct
18 Correct 6 ms 724 KB Output is correct
19 Correct 4 ms 724 KB Output is correct
20 Correct 4 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 370 ms 4244 KB Output is correct
2 Correct 376 ms 4236 KB Output is correct
3 Correct 394 ms 4240 KB Output is correct
4 Correct 402 ms 4244 KB Output is correct
5 Correct 392 ms 4236 KB Output is correct
6 Correct 382 ms 4180 KB Output is correct
7 Correct 373 ms 4232 KB Output is correct
8 Correct 385 ms 4240 KB Output is correct
9 Correct 384 ms 4180 KB Output is correct
10 Correct 375 ms 4248 KB Output is correct
11 Correct 382 ms 4236 KB Output is correct
12 Correct 409 ms 4236 KB Output is correct
13 Correct 387 ms 4240 KB Output is correct
14 Correct 383 ms 4232 KB Output is correct
15 Correct 376 ms 4236 KB Output is correct
16 Correct 68 ms 1004 KB Output is correct
17 Correct 76 ms 1068 KB Output is correct
18 Correct 67 ms 1028 KB Output is correct
19 Correct 71 ms 1068 KB Output is correct
20 Correct 68 ms 1040 KB Output is correct
21 Correct 25 ms 3796 KB Output is correct
22 Correct 26 ms 3916 KB Output is correct
23 Correct 31 ms 3784 KB Output is correct
24 Correct 27 ms 3796 KB Output is correct
25 Correct 25 ms 3788 KB Output is correct
26 Correct 23 ms 3796 KB Output is correct
27 Correct 25 ms 3796 KB Output is correct
28 Correct 23 ms 3784 KB Output is correct
29 Correct 25 ms 3668 KB Output is correct
30 Correct 368 ms 4236 KB Output is correct
31 Correct 364 ms 4248 KB Output is correct
32 Correct 365 ms 4236 KB Output is correct
33 Correct 346 ms 4248 KB Output is correct
34 Correct 374 ms 4232 KB Output is correct
35 Correct 336 ms 4180 KB Output is correct
36 Correct 359 ms 4240 KB Output is correct
37 Correct 350 ms 4236 KB Output is correct
38 Correct 356 ms 4228 KB Output is correct
39 Correct 12 ms 1108 KB Output is correct
40 Correct 9 ms 1152 KB Output is correct
41 Correct 8 ms 1108 KB Output is correct
42 Correct 9 ms 1116 KB Output is correct
43 Correct 11 ms 1108 KB Output is correct
44 Correct 9 ms 1116 KB Output is correct
45 Correct 10 ms 1096 KB Output is correct
46 Correct 10 ms 1096 KB Output is correct
47 Correct 10 ms 1108 KB Output is correct
48 Correct 13 ms 1108 KB Output is correct
49 Correct 10 ms 1096 KB Output is correct
50 Correct 10 ms 1108 KB Output is correct
51 Correct 9 ms 1108 KB Output is correct
52 Correct 9 ms 1108 KB Output is correct
53 Correct 9 ms 1124 KB Output is correct
54 Correct 5 ms 724 KB Output is correct
55 Correct 4 ms 736 KB Output is correct
56 Correct 6 ms 724 KB Output is correct
57 Correct 4 ms 724 KB Output is correct
58 Correct 4 ms 724 KB Output is correct
59 Correct 965 ms 4252 KB Output is correct
60 Correct 958 ms 4252 KB Output is correct
61 Correct 974 ms 4264 KB Output is correct
62 Correct 1027 ms 4180 KB Output is correct
63 Correct 975 ms 4300 KB Output is correct
64 Correct 1145 ms 4180 KB Output is correct
65 Correct 1094 ms 4252 KB Output is correct
66 Correct 1073 ms 4260 KB Output is correct
67 Correct 1087 ms 4252 KB Output is correct
68 Correct 1127 ms 4252 KB Output is correct
69 Correct 939 ms 4256 KB Output is correct
70 Correct 968 ms 4264 KB Output is correct
71 Correct 955 ms 4248 KB Output is correct
72 Correct 990 ms 4252 KB Output is correct
73 Correct 998 ms 4256 KB Output is correct
74 Correct 103 ms 980 KB Output is correct
75 Correct 101 ms 980 KB Output is correct
76 Correct 105 ms 1060 KB Output is correct
77 Correct 99 ms 980 KB Output is correct
78 Correct 99 ms 1040 KB Output is correct