답안 #403429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403429 2021-05-13T07:24:07 Z myrcella Boat (APIO16_boat) C++17
100 / 100
1133 ms 8420 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn=1e3+10;

int n;
int f[2][maxn][maxn];
int a[maxn],b[maxn];
map <int,int> mp;
int pm[maxn];
ll inv[maxn];
int sum[maxn];

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie();
	cin>>n;
	rep(i,1,maxn) inv[i]=p0w(i,mod-2);
	mp[0]=1;
	rep(i,1,n+1) cin>>a[i]>>b[i],a[i]--,mp[a[i]]=mp[b[i]]=1;
	int tot=0;
	for (auto &it:mp) it.se=tot,pm[tot++]=it.fi;
	int lst=0,cur=1;
	f[lst][0][0]=1;
	rep(i,1,n+1) {
		memset(sum,0,sizeof(sum));
		memset(f[cur],0,sizeof(f[cur]));
		rep(j,0,tot) 
			rep(k,0,i) {
				if (f[lst][j][k]==0) continue;
				//doesn't choose
				inc(f[cur][j][k],f[lst][j][k]); 
				inc(sum[j],f[lst][j][k]);
//				cout<<i-1<<" "<<j<<" "<<k<<" "<<f[lst][j][k]<<endl;
			}
//		debug(sum[0]),debug(sum[1]),debug(sum[2]);
		rep(j,mp[a[i]]+1,mp[b[i]]+1) {
			rep(k,0,i) {	
				//choose from the same segment
				if (pm[j]-pm[j-1]>=k+1) inc(f[cur][j][k+1],1ll*f[lst][j][k]*(pm[j]-pm[j-1]-k)%mod*inv[k+1]%mod);
			}
		}
		rep(j,1,tot) inc(sum[j],sum[j-1]);
//		debug(sum[1]),debug(sum[2]),debug(sum[3]);
//		debug(a[i]),debug(b[i]),debug(mp[a[i]]),debug(mp[b[i]]);
		rep(j,mp[a[i]],mp[b[i]]) {
			//start from a new segment
			inc(f[cur][j+1][1],1ll*sum[j]*(pm[j+1]-pm[j])%mod);
		}
		
		swap(lst,cur);
	}
	int ans=0;
	rep(i,1,tot)
		rep(j,1,n+1) inc(ans,f[lst][i][j]);
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 8364 KB Output is correct
2 Correct 290 ms 8352 KB Output is correct
3 Correct 286 ms 8352 KB Output is correct
4 Correct 291 ms 8372 KB Output is correct
5 Correct 300 ms 8268 KB Output is correct
6 Correct 283 ms 8364 KB Output is correct
7 Correct 296 ms 8356 KB Output is correct
8 Correct 314 ms 8268 KB Output is correct
9 Correct 300 ms 8268 KB Output is correct
10 Correct 298 ms 8348 KB Output is correct
11 Correct 295 ms 8356 KB Output is correct
12 Correct 298 ms 8268 KB Output is correct
13 Correct 295 ms 8352 KB Output is correct
14 Correct 298 ms 8360 KB Output is correct
15 Correct 288 ms 8388 KB Output is correct
16 Correct 171 ms 8324 KB Output is correct
17 Correct 176 ms 8332 KB Output is correct
18 Correct 171 ms 8308 KB Output is correct
19 Correct 169 ms 8316 KB Output is correct
20 Correct 159 ms 8308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 8364 KB Output is correct
2 Correct 290 ms 8352 KB Output is correct
3 Correct 286 ms 8352 KB Output is correct
4 Correct 291 ms 8372 KB Output is correct
5 Correct 300 ms 8268 KB Output is correct
6 Correct 283 ms 8364 KB Output is correct
7 Correct 296 ms 8356 KB Output is correct
8 Correct 314 ms 8268 KB Output is correct
9 Correct 300 ms 8268 KB Output is correct
10 Correct 298 ms 8348 KB Output is correct
11 Correct 295 ms 8356 KB Output is correct
12 Correct 298 ms 8268 KB Output is correct
13 Correct 295 ms 8352 KB Output is correct
14 Correct 298 ms 8360 KB Output is correct
15 Correct 288 ms 8388 KB Output is correct
16 Correct 171 ms 8324 KB Output is correct
17 Correct 176 ms 8332 KB Output is correct
18 Correct 171 ms 8308 KB Output is correct
19 Correct 169 ms 8316 KB Output is correct
20 Correct 159 ms 8308 KB Output is correct
21 Correct 325 ms 8344 KB Output is correct
22 Correct 340 ms 8356 KB Output is correct
23 Correct 351 ms 8360 KB Output is correct
24 Correct 347 ms 8388 KB Output is correct
25 Correct 336 ms 8268 KB Output is correct
26 Correct 353 ms 8268 KB Output is correct
27 Correct 356 ms 8352 KB Output is correct
28 Correct 350 ms 8268 KB Output is correct
29 Correct 343 ms 8352 KB Output is correct
30 Correct 294 ms 8368 KB Output is correct
31 Correct 295 ms 8368 KB Output is correct
32 Correct 296 ms 8268 KB Output is correct
33 Correct 291 ms 8420 KB Output is correct
34 Correct 347 ms 8364 KB Output is correct
35 Correct 301 ms 8276 KB Output is correct
36 Correct 301 ms 8372 KB Output is correct
37 Correct 286 ms 8268 KB Output is correct
38 Correct 303 ms 8360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 8268 KB Output is correct
2 Correct 37 ms 8268 KB Output is correct
3 Correct 46 ms 8268 KB Output is correct
4 Correct 42 ms 8268 KB Output is correct
5 Correct 40 ms 8268 KB Output is correct
6 Correct 38 ms 8268 KB Output is correct
7 Correct 40 ms 8312 KB Output is correct
8 Correct 41 ms 8268 KB Output is correct
9 Correct 44 ms 8268 KB Output is correct
10 Correct 45 ms 8204 KB Output is correct
11 Correct 40 ms 8268 KB Output is correct
12 Correct 52 ms 8312 KB Output is correct
13 Correct 39 ms 8268 KB Output is correct
14 Correct 38 ms 8268 KB Output is correct
15 Correct 37 ms 8268 KB Output is correct
16 Correct 49 ms 8268 KB Output is correct
17 Correct 37 ms 8396 KB Output is correct
18 Correct 46 ms 8268 KB Output is correct
19 Correct 40 ms 8268 KB Output is correct
20 Correct 36 ms 8308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 8364 KB Output is correct
2 Correct 290 ms 8352 KB Output is correct
3 Correct 286 ms 8352 KB Output is correct
4 Correct 291 ms 8372 KB Output is correct
5 Correct 300 ms 8268 KB Output is correct
6 Correct 283 ms 8364 KB Output is correct
7 Correct 296 ms 8356 KB Output is correct
8 Correct 314 ms 8268 KB Output is correct
9 Correct 300 ms 8268 KB Output is correct
10 Correct 298 ms 8348 KB Output is correct
11 Correct 295 ms 8356 KB Output is correct
12 Correct 298 ms 8268 KB Output is correct
13 Correct 295 ms 8352 KB Output is correct
14 Correct 298 ms 8360 KB Output is correct
15 Correct 288 ms 8388 KB Output is correct
16 Correct 171 ms 8324 KB Output is correct
17 Correct 176 ms 8332 KB Output is correct
18 Correct 171 ms 8308 KB Output is correct
19 Correct 169 ms 8316 KB Output is correct
20 Correct 159 ms 8308 KB Output is correct
21 Correct 325 ms 8344 KB Output is correct
22 Correct 340 ms 8356 KB Output is correct
23 Correct 351 ms 8360 KB Output is correct
24 Correct 347 ms 8388 KB Output is correct
25 Correct 336 ms 8268 KB Output is correct
26 Correct 353 ms 8268 KB Output is correct
27 Correct 356 ms 8352 KB Output is correct
28 Correct 350 ms 8268 KB Output is correct
29 Correct 343 ms 8352 KB Output is correct
30 Correct 294 ms 8368 KB Output is correct
31 Correct 295 ms 8368 KB Output is correct
32 Correct 296 ms 8268 KB Output is correct
33 Correct 291 ms 8420 KB Output is correct
34 Correct 347 ms 8364 KB Output is correct
35 Correct 301 ms 8276 KB Output is correct
36 Correct 301 ms 8372 KB Output is correct
37 Correct 286 ms 8268 KB Output is correct
38 Correct 303 ms 8360 KB Output is correct
39 Correct 37 ms 8268 KB Output is correct
40 Correct 37 ms 8268 KB Output is correct
41 Correct 46 ms 8268 KB Output is correct
42 Correct 42 ms 8268 KB Output is correct
43 Correct 40 ms 8268 KB Output is correct
44 Correct 38 ms 8268 KB Output is correct
45 Correct 40 ms 8312 KB Output is correct
46 Correct 41 ms 8268 KB Output is correct
47 Correct 44 ms 8268 KB Output is correct
48 Correct 45 ms 8204 KB Output is correct
49 Correct 40 ms 8268 KB Output is correct
50 Correct 52 ms 8312 KB Output is correct
51 Correct 39 ms 8268 KB Output is correct
52 Correct 38 ms 8268 KB Output is correct
53 Correct 37 ms 8268 KB Output is correct
54 Correct 49 ms 8268 KB Output is correct
55 Correct 37 ms 8396 KB Output is correct
56 Correct 46 ms 8268 KB Output is correct
57 Correct 40 ms 8268 KB Output is correct
58 Correct 36 ms 8308 KB Output is correct
59 Correct 889 ms 8360 KB Output is correct
60 Correct 819 ms 8368 KB Output is correct
61 Correct 810 ms 8388 KB Output is correct
62 Correct 868 ms 8360 KB Output is correct
63 Correct 834 ms 8376 KB Output is correct
64 Correct 1110 ms 8388 KB Output is correct
65 Correct 1133 ms 8364 KB Output is correct
66 Correct 1121 ms 8368 KB Output is correct
67 Correct 1127 ms 8360 KB Output is correct
68 Correct 1126 ms 8368 KB Output is correct
69 Correct 815 ms 8268 KB Output is correct
70 Correct 808 ms 8388 KB Output is correct
71 Correct 806 ms 8360 KB Output is correct
72 Correct 819 ms 8360 KB Output is correct
73 Correct 833 ms 8268 KB Output is correct
74 Correct 230 ms 8268 KB Output is correct
75 Correct 227 ms 8320 KB Output is correct
76 Correct 253 ms 8320 KB Output is correct
77 Correct 229 ms 8268 KB Output is correct
78 Correct 235 ms 8320 KB Output is correct