Submission #107341

# Submission time Handle Problem Language Result Execution time Memory
107341 2019-04-23T11:40:04 Z username Boat (APIO16_boat) C++14
100 / 100
729 ms 580 KB
#include<bits/stdc++.h>
#include<stdint.h>
#define int int64_t
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(int i=(j);i<(k);++i)
#define RREP(i,j,k) for(int i=(j)-1;i>=(k);--i)
#define MST(a,v) memset(a,(v),sizeof a)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define F first
#define S second
#define IOS cin.tie(0),ios_base::sync_with_stdio(false)
#define add(x,y) x=(x+y)%mo
 
const int maxn=509,mo=1e9L+7;
int n,a[maxn],b[maxn],dp[maxn],inv[maxn];
vector<int>p;
 
int qp(int x,int t){
	int re=1;
	while(t){
		if(t&1)re=re*x%mo;
		x=x*x%mo,t>>=1;
	}
	return re;
}
 
main(){
	IOS;
	cin>>n;
	REP(i,1,n+1)inv[i]=qp(i,mo-2);
	REP(i,0,n)cin>>a[i]>>b[i],++b[i],p.pb(a[i]),p.pb(b[i]);
	sort(ALL(p));
	p.resize(unique(ALL(p))-p.begin());
	REP(i,0,n)a[i]=find(ALL(p),a[i])-p.begin(),b[i]=find(ALL(p),b[i])-p.begin();
	dp[0]=1;
	REP(i,0,p.size()-1){
		int l=p[i+1]-p[i];
		RREP(j,n,0){
			if(a[j]<=i&&i<b[j]){
				int c=l,t=1;
				RREP(k,j+1,0){
					add(dp[j+1],c*dp[k]%mo);
					if(k&&a[k-1]<=i&&i<b[k-1])c=c*(t+l)%mo*inv[t+1]%mo,++t;
				}
			}
		}
	}
	int sum=0;
	REP(i,0,n)add(sum,dp[i+1]);
	cout<<sum<<endl;
}

Compilation message

boat.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
boat.cpp: In function 'int main()':
boat.cpp:6:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,j,k) for(int i=(j);i<(k);++i)
                                   ^
boat.cpp:38:2: note: in expansion of macro 'REP'
  REP(i,0,p.size()-1){
  ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 428 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 20 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 428 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 20 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 325 ms 384 KB Output is correct
22 Correct 296 ms 384 KB Output is correct
23 Correct 287 ms 500 KB Output is correct
24 Correct 298 ms 580 KB Output is correct
25 Correct 325 ms 384 KB Output is correct
26 Correct 586 ms 384 KB Output is correct
27 Correct 568 ms 508 KB Output is correct
28 Correct 553 ms 384 KB Output is correct
29 Correct 526 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 7 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 7 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 428 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 20 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 325 ms 384 KB Output is correct
22 Correct 296 ms 384 KB Output is correct
23 Correct 287 ms 500 KB Output is correct
24 Correct 298 ms 580 KB Output is correct
25 Correct 325 ms 384 KB Output is correct
26 Correct 586 ms 384 KB Output is correct
27 Correct 568 ms 508 KB Output is correct
28 Correct 553 ms 384 KB Output is correct
29 Correct 526 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 6 ms 384 KB Output is correct
36 Correct 7 ms 384 KB Output is correct
37 Correct 7 ms 384 KB Output is correct
38 Correct 8 ms 384 KB Output is correct
39 Correct 6 ms 384 KB Output is correct
40 Correct 4 ms 384 KB Output is correct
41 Correct 5 ms 512 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Correct 6 ms 384 KB Output is correct
44 Correct 8 ms 384 KB Output is correct
45 Correct 7 ms 384 KB Output is correct
46 Correct 7 ms 384 KB Output is correct
47 Correct 8 ms 384 KB Output is correct
48 Correct 8 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 4 ms 384 KB Output is correct
55 Correct 4 ms 384 KB Output is correct
56 Correct 4 ms 384 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 4 ms 384 KB Output is correct
59 Correct 346 ms 416 KB Output is correct
60 Correct 302 ms 508 KB Output is correct
61 Correct 303 ms 504 KB Output is correct
62 Correct 349 ms 512 KB Output is correct
63 Correct 313 ms 512 KB Output is correct
64 Correct 670 ms 504 KB Output is correct
65 Correct 729 ms 384 KB Output is correct
66 Correct 639 ms 504 KB Output is correct
67 Correct 627 ms 508 KB Output is correct
68 Correct 617 ms 504 KB Output is correct
69 Correct 260 ms 504 KB Output is correct
70 Correct 262 ms 384 KB Output is correct
71 Correct 281 ms 504 KB Output is correct
72 Correct 264 ms 384 KB Output is correct
73 Correct 296 ms 412 KB Output is correct
74 Correct 74 ms 384 KB Output is correct
75 Correct 66 ms 384 KB Output is correct
76 Correct 69 ms 384 KB Output is correct
77 Correct 78 ms 384 KB Output is correct
78 Correct 74 ms 416 KB Output is correct