Submission #494911

# Submission time Handle Problem Language Result Execution time Memory
494911 2021-12-17T12:56:24 Z jamezzz Boat (APIO16_boat) C++17
100 / 100
1649 ms 8784 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)a*b)%mod);
}

inline int rd(){
    int x=0;
    char ch=getchar_unlocked();
    while(ch<'0'||ch>'9')ch=getchar_unlocked();
    while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar_unlocked();
	}
    return x;
}

int n,m,a[505],b[505],memo[505][1005],c[1005][505],c2[505][505],w[1005][505],inv[505];
vector<int> v[1005],d;

int fp(int a,int x){
	if(x==0)return 1;
	int t=fp(a,x/2);
	int r=mult(t,t);
	if(x%2)r=mult(r,a);
	return r;
}

int choose(int a,int b){
	int r=1;
	for(int i=a-b+1;i<=a;++i)r=mult(r,i);
	for(int i=1;i<=b;++i)r=mult(r,inv[i]);
	return r;
}

int dp(int i,int j){//covered up to the ith segment,now deciding for jth segment
	if(i==n)return 1;
	if(j==m)return (i!=0);
	if(memo[i][j]!=-1)return memo[i][j];
	int s=upper_bound(all(v[j]),i)-v[j].begin();
	int ans=dp(i,j+1);
	for(int t=s;t<sz(v[j]);++t){
		ans=add(ans,mult(w[j][t-s+1],dp(v[j][t],j+1)));
	}
	return memo[i][j]=ans;
}

int main(){
	sf("%d",&n);
	for(int i=1;i<=n;++i){
		sf("%d%d",&a[i],&b[i]);
		d.pb(a[i]);d.pb(b[i]+1);
	}
	disc(d);m=sz(d);d.pb(d.back()+1);
	for(int i=1;i<=n;++i){
		for(int j=0;j<m;++j){
			if(a[i]<=d[j]&&d[j]<=b[i])v[j].pb(i);
		}
	}
	for(int i=1;i<=n;++i)inv[i]=fp(i,mod-2);
	for(int i=0;i<m;++i){
		int a=d[i+1]-d[i];
		for(int b=1;b<=sz(v[i]);++b){
			c[i][b]=choose(a,b);
		}
	}
	for(int i=0;i<=n;++i){
		for(int j=0;j<=i;++j){
			c2[i][j]=choose(i,j);
		}
	}
	for(int i=0;i<m;++i){
		int a=d[i+1]-d[i];
		for(int b=1;b<=sz(v[i]);++b){
			for(int k=0;k<b;++k){
				w[i][b]=add(w[i][b],mult(c[i][k+1],c2[b-1][k]));
			}
		}
	}
	memset(memo,-1,sizeof memo);
	pf("%d\n",dp(0,0));
}

/*
2
1 2
2 3
*/

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:112:7: warning: unused variable 'a' [-Wunused-variable]
  112 |   int a=d[i+1]-d[i];
      |       ^
boat.cpp:88:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |  sf("%d",&n);
      |    ^
boat.cpp:90:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   sf("%d%d",&a[i],&b[i]);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 226 ms 7508 KB Output is correct
2 Correct 228 ms 7244 KB Output is correct
3 Correct 223 ms 7484 KB Output is correct
4 Correct 232 ms 7224 KB Output is correct
5 Correct 219 ms 7308 KB Output is correct
6 Correct 227 ms 7352 KB Output is correct
7 Correct 226 ms 7364 KB Output is correct
8 Correct 214 ms 7312 KB Output is correct
9 Correct 220 ms 7248 KB Output is correct
10 Correct 215 ms 7240 KB Output is correct
11 Correct 215 ms 7236 KB Output is correct
12 Correct 219 ms 7284 KB Output is correct
13 Correct 229 ms 7316 KB Output is correct
14 Correct 215 ms 7228 KB Output is correct
15 Correct 223 ms 7232 KB Output is correct
16 Correct 224 ms 3988 KB Output is correct
17 Correct 211 ms 4036 KB Output is correct
18 Correct 209 ms 3952 KB Output is correct
19 Correct 213 ms 4108 KB Output is correct
20 Correct 211 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 7508 KB Output is correct
2 Correct 228 ms 7244 KB Output is correct
3 Correct 223 ms 7484 KB Output is correct
4 Correct 232 ms 7224 KB Output is correct
5 Correct 219 ms 7308 KB Output is correct
6 Correct 227 ms 7352 KB Output is correct
7 Correct 226 ms 7364 KB Output is correct
8 Correct 214 ms 7312 KB Output is correct
9 Correct 220 ms 7248 KB Output is correct
10 Correct 215 ms 7240 KB Output is correct
11 Correct 215 ms 7236 KB Output is correct
12 Correct 219 ms 7284 KB Output is correct
13 Correct 229 ms 7316 KB Output is correct
14 Correct 215 ms 7228 KB Output is correct
15 Correct 223 ms 7232 KB Output is correct
16 Correct 224 ms 3988 KB Output is correct
17 Correct 211 ms 4036 KB Output is correct
18 Correct 209 ms 3952 KB Output is correct
19 Correct 213 ms 4108 KB Output is correct
20 Correct 211 ms 4036 KB Output is correct
21 Correct 744 ms 7832 KB Output is correct
22 Correct 729 ms 8008 KB Output is correct
23 Correct 684 ms 7836 KB Output is correct
24 Correct 736 ms 7840 KB Output is correct
25 Correct 745 ms 7844 KB Output is correct
26 Correct 1305 ms 8048 KB Output is correct
27 Correct 1305 ms 8208 KB Output is correct
28 Correct 1312 ms 8132 KB Output is correct
29 Correct 1280 ms 8176 KB Output is correct
30 Correct 224 ms 7288 KB Output is correct
31 Correct 223 ms 7376 KB Output is correct
32 Correct 228 ms 7248 KB Output is correct
33 Correct 233 ms 7392 KB Output is correct
34 Correct 225 ms 7252 KB Output is correct
35 Correct 218 ms 7236 KB Output is correct
36 Correct 219 ms 7268 KB Output is correct
37 Correct 218 ms 7248 KB Output is correct
38 Correct 220 ms 7368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3280 KB Output is correct
2 Correct 7 ms 3276 KB Output is correct
3 Correct 8 ms 3276 KB Output is correct
4 Correct 8 ms 3380 KB Output is correct
5 Correct 11 ms 3380 KB Output is correct
6 Correct 15 ms 3276 KB Output is correct
7 Correct 15 ms 3400 KB Output is correct
8 Correct 16 ms 3400 KB Output is correct
9 Correct 15 ms 3396 KB Output is correct
10 Correct 16 ms 3500 KB Output is correct
11 Correct 9 ms 3336 KB Output is correct
12 Correct 9 ms 3260 KB Output is correct
13 Correct 9 ms 3368 KB Output is correct
14 Correct 9 ms 3384 KB Output is correct
15 Correct 10 ms 3272 KB Output is correct
16 Correct 7 ms 3020 KB Output is correct
17 Correct 7 ms 3020 KB Output is correct
18 Correct 6 ms 3020 KB Output is correct
19 Correct 6 ms 3020 KB Output is correct
20 Correct 7 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 7508 KB Output is correct
2 Correct 228 ms 7244 KB Output is correct
3 Correct 223 ms 7484 KB Output is correct
4 Correct 232 ms 7224 KB Output is correct
5 Correct 219 ms 7308 KB Output is correct
6 Correct 227 ms 7352 KB Output is correct
7 Correct 226 ms 7364 KB Output is correct
8 Correct 214 ms 7312 KB Output is correct
9 Correct 220 ms 7248 KB Output is correct
10 Correct 215 ms 7240 KB Output is correct
11 Correct 215 ms 7236 KB Output is correct
12 Correct 219 ms 7284 KB Output is correct
13 Correct 229 ms 7316 KB Output is correct
14 Correct 215 ms 7228 KB Output is correct
15 Correct 223 ms 7232 KB Output is correct
16 Correct 224 ms 3988 KB Output is correct
17 Correct 211 ms 4036 KB Output is correct
18 Correct 209 ms 3952 KB Output is correct
19 Correct 213 ms 4108 KB Output is correct
20 Correct 211 ms 4036 KB Output is correct
21 Correct 744 ms 7832 KB Output is correct
22 Correct 729 ms 8008 KB Output is correct
23 Correct 684 ms 7836 KB Output is correct
24 Correct 736 ms 7840 KB Output is correct
25 Correct 745 ms 7844 KB Output is correct
26 Correct 1305 ms 8048 KB Output is correct
27 Correct 1305 ms 8208 KB Output is correct
28 Correct 1312 ms 8132 KB Output is correct
29 Correct 1280 ms 8176 KB Output is correct
30 Correct 224 ms 7288 KB Output is correct
31 Correct 223 ms 7376 KB Output is correct
32 Correct 228 ms 7248 KB Output is correct
33 Correct 233 ms 7392 KB Output is correct
34 Correct 225 ms 7252 KB Output is correct
35 Correct 218 ms 7236 KB Output is correct
36 Correct 219 ms 7268 KB Output is correct
37 Correct 218 ms 7248 KB Output is correct
38 Correct 220 ms 7368 KB Output is correct
39 Correct 9 ms 3280 KB Output is correct
40 Correct 7 ms 3276 KB Output is correct
41 Correct 8 ms 3276 KB Output is correct
42 Correct 8 ms 3380 KB Output is correct
43 Correct 11 ms 3380 KB Output is correct
44 Correct 15 ms 3276 KB Output is correct
45 Correct 15 ms 3400 KB Output is correct
46 Correct 16 ms 3400 KB Output is correct
47 Correct 15 ms 3396 KB Output is correct
48 Correct 16 ms 3500 KB Output is correct
49 Correct 9 ms 3336 KB Output is correct
50 Correct 9 ms 3260 KB Output is correct
51 Correct 9 ms 3368 KB Output is correct
52 Correct 9 ms 3384 KB Output is correct
53 Correct 10 ms 3272 KB Output is correct
54 Correct 7 ms 3020 KB Output is correct
55 Correct 7 ms 3020 KB Output is correct
56 Correct 6 ms 3020 KB Output is correct
57 Correct 6 ms 3020 KB Output is correct
58 Correct 7 ms 2892 KB Output is correct
59 Correct 951 ms 8332 KB Output is correct
60 Correct 848 ms 8256 KB Output is correct
61 Correct 808 ms 8284 KB Output is correct
62 Correct 902 ms 8600 KB Output is correct
63 Correct 866 ms 8308 KB Output is correct
64 Correct 1649 ms 8784 KB Output is correct
65 Correct 1573 ms 8704 KB Output is correct
66 Correct 1631 ms 8644 KB Output is correct
67 Correct 1620 ms 8640 KB Output is correct
68 Correct 1629 ms 8696 KB Output is correct
69 Correct 913 ms 8252 KB Output is correct
70 Correct 867 ms 8224 KB Output is correct
71 Correct 855 ms 8324 KB Output is correct
72 Correct 864 ms 8288 KB Output is correct
73 Correct 899 ms 8324 KB Output is correct
74 Correct 316 ms 4160 KB Output is correct
75 Correct 309 ms 4172 KB Output is correct
76 Correct 338 ms 4164 KB Output is correct
77 Correct 335 ms 4352 KB Output is correct
78 Correct 336 ms 4288 KB Output is correct