# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20692 |
2017-02-13T14:03:23 Z |
Namnamseo |
Boat (APIO16_boat) |
C++14 |
|
683 ms |
5212 KB |
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define M (int(1e9)+7)
using namespace std;
typedef pair<int,int> pp;
pp data[510];
vector<int> pt;
int length[1010];
int n;
void read(int& x){ scanf("%d",&x); }
template<typename T1, typename... T2>
void read(T1& x,T2&... args){ read(x); read(args...); }
int dp[510][1010];
int pref[510][1010];
int level[1010];
typedef long long ll;
typedef pair<ll,ll> pli;
pli ext_gcd(int a,int b){
if(a%b == 0) return {0,1};
pli tmp=ext_gcd(b,a%b);
ll x=tmp.second, y=(tmp.first - (a/b)*1LL*tmp.second);
if(x <= -b){
ll t=((-x+b-1) / b);
x += t*b; y -= t*a;
}
if(y <= -a){
ll t=((-y+a-1) / a);
y += t*a; x -= t*b;
}
return {x,y};
}
int mod_inv(int x){
return (M+ext_gcd(x, M).first)%M;
}
int modinv_table[510];
void build_modinv(){
modinv_table[1]=1;
for(int i=2; i<=500; ++i) modinv_table[i]=mod_inv(i);
}
int combi(int a,int b){
if(a<b) return 0;
ll ret=1;
for(;b>=1;){
ret *= a; ret %= M;
ret *= modinv_table[b]; ret %= M;
--a; --b;
}
return ret;
}
int main(){
build_modinv();
{
read(n);
for(int i=1;i<=n;++i){
int a,b; read(a,b); data[i]={a,b};
pt.pb(a);
pt.pb(b+1);
}
}
pt.pb(0);
sort(all(pt));
pt.erase(unique(all(pt)), pt.end());
dp[0][0]=1; pref[0][0]=1;
for(int i=1; i<pt.size(); ++i) {
pref[0][i] = 1;
length[i-1] = pt[i]-pt[i-1];
}
{
for(int i=1; i<=n; ++i){
int l=lower_bound(all(pt), data[i].first)-pt.begin();
int r=upper_bound(all(pt), data[i].second)-pt.begin()-1;
for(int j=l; j<=r; ++j){
int came = pref[i-1][j-1];
int ind=0;
dp[i][j]=(dp[i][j]+length[j]*((ll)came)%M)%M;
ll lastcombi = length[j]-1;
for(int k=i+1; k<=n; ++k){
if(data[k].first<=pt[j] && pt[j+1]<=data[k].second+1){
++ind;
lastcombi *= length[j]+ind-1; lastcombi %= M;
lastcombi *= modinv_table[ind+1]; lastcombi %= M;
dp[k][j] = (dp[k][j] + lastcombi*1LL*came%M)%M;
}
}
}
pref[i][0]=pref[i-1][0] + dp[i][0];
for(int j=1; j<pt.size()-1; ++j){
pref[i][j]=((ll)pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+dp[i][j]+M)%M;
}
}
printf("%d\n", (pref[n][pt.size()-2]+M-1)%M);
}
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<pt.size(); ++i) {
^
boat.cpp:100:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=1; j<pt.size()-1; ++j){
^
boat.cpp: In function 'void read(int&)':
boat.cpp:15:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
void read(int& x){ scanf("%d",&x); }
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5212 KB |
Output is correct |
2 |
Correct |
6 ms |
5212 KB |
Output is correct |
3 |
Correct |
6 ms |
5212 KB |
Output is correct |
4 |
Correct |
6 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
6 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
6 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
0 ms |
5212 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
5212 KB |
Output is correct |
15 |
Correct |
6 ms |
5212 KB |
Output is correct |
16 |
Correct |
3 ms |
5212 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
0 ms |
5212 KB |
Output is correct |
19 |
Correct |
3 ms |
5212 KB |
Output is correct |
20 |
Correct |
0 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5212 KB |
Output is correct |
2 |
Correct |
6 ms |
5212 KB |
Output is correct |
3 |
Correct |
6 ms |
5212 KB |
Output is correct |
4 |
Correct |
6 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
6 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
6 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
0 ms |
5212 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
5212 KB |
Output is correct |
15 |
Correct |
6 ms |
5212 KB |
Output is correct |
16 |
Correct |
3 ms |
5212 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
0 ms |
5212 KB |
Output is correct |
19 |
Correct |
3 ms |
5212 KB |
Output is correct |
20 |
Correct |
0 ms |
5212 KB |
Output is correct |
21 |
Correct |
266 ms |
5212 KB |
Output is correct |
22 |
Correct |
256 ms |
5212 KB |
Output is correct |
23 |
Correct |
236 ms |
5212 KB |
Output is correct |
24 |
Correct |
259 ms |
5212 KB |
Output is correct |
25 |
Correct |
276 ms |
5212 KB |
Output is correct |
26 |
Correct |
546 ms |
5212 KB |
Output is correct |
27 |
Correct |
583 ms |
5212 KB |
Output is correct |
28 |
Correct |
553 ms |
5212 KB |
Output is correct |
29 |
Correct |
549 ms |
5212 KB |
Output is correct |
30 |
Correct |
6 ms |
5212 KB |
Output is correct |
31 |
Correct |
6 ms |
5212 KB |
Output is correct |
32 |
Correct |
9 ms |
5212 KB |
Output is correct |
33 |
Correct |
6 ms |
5212 KB |
Output is correct |
34 |
Correct |
9 ms |
5212 KB |
Output is correct |
35 |
Correct |
6 ms |
5212 KB |
Output is correct |
36 |
Correct |
9 ms |
5212 KB |
Output is correct |
37 |
Correct |
6 ms |
5212 KB |
Output is correct |
38 |
Correct |
6 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5212 KB |
Output is correct |
2 |
Correct |
0 ms |
5212 KB |
Output is correct |
3 |
Correct |
0 ms |
5212 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
6 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
3 ms |
5212 KB |
Output is correct |
16 |
Correct |
0 ms |
5212 KB |
Output is correct |
17 |
Correct |
0 ms |
5212 KB |
Output is correct |
18 |
Correct |
0 ms |
5212 KB |
Output is correct |
19 |
Correct |
0 ms |
5212 KB |
Output is correct |
20 |
Correct |
0 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5212 KB |
Output is correct |
2 |
Correct |
6 ms |
5212 KB |
Output is correct |
3 |
Correct |
6 ms |
5212 KB |
Output is correct |
4 |
Correct |
6 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
5212 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
6 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
6 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
5212 KB |
Output is correct |
12 |
Correct |
0 ms |
5212 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
5212 KB |
Output is correct |
15 |
Correct |
6 ms |
5212 KB |
Output is correct |
16 |
Correct |
3 ms |
5212 KB |
Output is correct |
17 |
Correct |
3 ms |
5212 KB |
Output is correct |
18 |
Correct |
0 ms |
5212 KB |
Output is correct |
19 |
Correct |
3 ms |
5212 KB |
Output is correct |
20 |
Correct |
0 ms |
5212 KB |
Output is correct |
21 |
Correct |
266 ms |
5212 KB |
Output is correct |
22 |
Correct |
256 ms |
5212 KB |
Output is correct |
23 |
Correct |
236 ms |
5212 KB |
Output is correct |
24 |
Correct |
259 ms |
5212 KB |
Output is correct |
25 |
Correct |
276 ms |
5212 KB |
Output is correct |
26 |
Correct |
546 ms |
5212 KB |
Output is correct |
27 |
Correct |
583 ms |
5212 KB |
Output is correct |
28 |
Correct |
553 ms |
5212 KB |
Output is correct |
29 |
Correct |
549 ms |
5212 KB |
Output is correct |
30 |
Correct |
6 ms |
5212 KB |
Output is correct |
31 |
Correct |
6 ms |
5212 KB |
Output is correct |
32 |
Correct |
9 ms |
5212 KB |
Output is correct |
33 |
Correct |
6 ms |
5212 KB |
Output is correct |
34 |
Correct |
9 ms |
5212 KB |
Output is correct |
35 |
Correct |
6 ms |
5212 KB |
Output is correct |
36 |
Correct |
9 ms |
5212 KB |
Output is correct |
37 |
Correct |
6 ms |
5212 KB |
Output is correct |
38 |
Correct |
6 ms |
5212 KB |
Output is correct |
39 |
Correct |
3 ms |
5212 KB |
Output is correct |
40 |
Correct |
0 ms |
5212 KB |
Output is correct |
41 |
Correct |
0 ms |
5212 KB |
Output is correct |
42 |
Correct |
3 ms |
5212 KB |
Output is correct |
43 |
Correct |
3 ms |
5212 KB |
Output is correct |
44 |
Correct |
3 ms |
5212 KB |
Output is correct |
45 |
Correct |
3 ms |
5212 KB |
Output is correct |
46 |
Correct |
3 ms |
5212 KB |
Output is correct |
47 |
Correct |
3 ms |
5212 KB |
Output is correct |
48 |
Correct |
6 ms |
5212 KB |
Output is correct |
49 |
Correct |
3 ms |
5212 KB |
Output is correct |
50 |
Correct |
3 ms |
5212 KB |
Output is correct |
51 |
Correct |
3 ms |
5212 KB |
Output is correct |
52 |
Correct |
3 ms |
5212 KB |
Output is correct |
53 |
Correct |
3 ms |
5212 KB |
Output is correct |
54 |
Correct |
0 ms |
5212 KB |
Output is correct |
55 |
Correct |
0 ms |
5212 KB |
Output is correct |
56 |
Correct |
0 ms |
5212 KB |
Output is correct |
57 |
Correct |
0 ms |
5212 KB |
Output is correct |
58 |
Correct |
0 ms |
5212 KB |
Output is correct |
59 |
Correct |
289 ms |
5212 KB |
Output is correct |
60 |
Correct |
266 ms |
5212 KB |
Output is correct |
61 |
Correct |
269 ms |
5212 KB |
Output is correct |
62 |
Correct |
299 ms |
5212 KB |
Output is correct |
63 |
Correct |
303 ms |
5212 KB |
Output is correct |
64 |
Correct |
639 ms |
5212 KB |
Output is correct |
65 |
Correct |
636 ms |
5212 KB |
Output is correct |
66 |
Correct |
616 ms |
5212 KB |
Output is correct |
67 |
Correct |
613 ms |
5212 KB |
Output is correct |
68 |
Correct |
683 ms |
5212 KB |
Output is correct |
69 |
Correct |
256 ms |
5212 KB |
Output is correct |
70 |
Correct |
269 ms |
5212 KB |
Output is correct |
71 |
Correct |
266 ms |
5212 KB |
Output is correct |
72 |
Correct |
283 ms |
5212 KB |
Output is correct |
73 |
Correct |
276 ms |
5212 KB |
Output is correct |
74 |
Correct |
69 ms |
5212 KB |
Output is correct |
75 |
Correct |
53 ms |
5212 KB |
Output is correct |
76 |
Correct |
63 ms |
5212 KB |
Output is correct |
77 |
Correct |
56 ms |
5212 KB |
Output is correct |
78 |
Correct |
66 ms |
5212 KB |
Output is correct |