# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
44900 |
2018-04-09T07:35:41 Z |
Kerim |
Boat (APIO16_boat) |
C++17 |
|
1503 ms |
2196 KB |
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define next nasa
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=505;
map<int,int>vis;
map<int,vector<int> >add,rem;
set<int>s;
vector<int>v;
int arr[N],inv[N],par[N],dp[N],DP[N][N];
int mod(ll x){
while(x<0)
x+=INF;
return (x%INF);
}
int Fe(int x,int y){
if(!y)
return 1;
int h=Fe(x,y/2);
h=mod(h*1LL*h);
if(y&1)
h=mod(h*1LL*x);
return h;
}
void pre(int x,int y){
arr[0]=1;
int bug=x;
for(int i=1;i<=min(bug,y);i++){
arr[i]=mod(arr[i-1]*1LL*x);x--;
arr[i]=mod(arr[i]*1LL*inv[i]);
}
}
int rec(int x,int y){
if(x<0)
return 0;
int &ret=DP[x][y];
if(~ret)
return ret;
if(!y)
return ret=mod(rec(x-1,y)+par[v[x]-1]);
return ret=mod(rec(x-1,y)+rec(x-1,y-1));
}
int main(){
//~ freopen("file.in", "r", stdin);
inv[0]=1;
for(int i=1;i<N;i++)
inv[i]=Fe(i,INF-2);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
int l,r;
scanf("%d%d",&l,&r);
vis[l]=vis[r+1]=1;
//~ cout<<"add "<<l<<endl;
//~ cout<<"rem "<<r+1<<endl;
add[l].pb(i);
rem[r+1].pb(i);
}
tr(itt,vis){
int now=itt->ff,next;
__typeof((vis).begin())tmp=itt;tmp++;
if(tmp!=vis.end())
next=tmp->ff;
else
break;
tr(it,add[now])
s.insert(*it);
tr(it,rem[now])
s.erase(*it);
if(s.size()){
int m=s.size();
pre(next-now,m);
par[0]=1;
for(int i=1;i<=n;i++)
par[i]=mod(par[i-1]+dp[i]);
v.clear();
tr(it,s)
v.pb(*it);
memset(DP,-1,sizeof DP);
for(int i=0;i<m;i++)
for(int j=0;j<=min(next-now-1,i);j++){
if(!j)
dp[v[i]]=mod(dp[v[i]]+mod(arr[j+1]*1LL*par[v[i]-1]));
else
dp[v[i]]=mod(dp[v[i]]+mod(arr[j+1]*1LL*rec(i-1,j-1)));
}
}
}
int ans=0;
for(int i=1;i<=n;i++)
ans=mod(ans+dp[i]);
printf("%d\n",ans);
return 0;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
boat.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&l,&r);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1528 KB |
Output is correct |
2 |
Correct |
33 ms |
1640 KB |
Output is correct |
3 |
Correct |
35 ms |
1844 KB |
Output is correct |
4 |
Correct |
34 ms |
1844 KB |
Output is correct |
5 |
Correct |
34 ms |
1844 KB |
Output is correct |
6 |
Correct |
32 ms |
1876 KB |
Output is correct |
7 |
Correct |
33 ms |
1876 KB |
Output is correct |
8 |
Correct |
31 ms |
1876 KB |
Output is correct |
9 |
Correct |
34 ms |
1876 KB |
Output is correct |
10 |
Correct |
32 ms |
1876 KB |
Output is correct |
11 |
Correct |
34 ms |
1876 KB |
Output is correct |
12 |
Correct |
35 ms |
1876 KB |
Output is correct |
13 |
Correct |
31 ms |
1876 KB |
Output is correct |
14 |
Correct |
30 ms |
1876 KB |
Output is correct |
15 |
Correct |
32 ms |
1876 KB |
Output is correct |
16 |
Correct |
8 ms |
1876 KB |
Output is correct |
17 |
Correct |
9 ms |
1876 KB |
Output is correct |
18 |
Correct |
9 ms |
1876 KB |
Output is correct |
19 |
Correct |
8 ms |
1876 KB |
Output is correct |
20 |
Correct |
10 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1528 KB |
Output is correct |
2 |
Correct |
33 ms |
1640 KB |
Output is correct |
3 |
Correct |
35 ms |
1844 KB |
Output is correct |
4 |
Correct |
34 ms |
1844 KB |
Output is correct |
5 |
Correct |
34 ms |
1844 KB |
Output is correct |
6 |
Correct |
32 ms |
1876 KB |
Output is correct |
7 |
Correct |
33 ms |
1876 KB |
Output is correct |
8 |
Correct |
31 ms |
1876 KB |
Output is correct |
9 |
Correct |
34 ms |
1876 KB |
Output is correct |
10 |
Correct |
32 ms |
1876 KB |
Output is correct |
11 |
Correct |
34 ms |
1876 KB |
Output is correct |
12 |
Correct |
35 ms |
1876 KB |
Output is correct |
13 |
Correct |
31 ms |
1876 KB |
Output is correct |
14 |
Correct |
30 ms |
1876 KB |
Output is correct |
15 |
Correct |
32 ms |
1876 KB |
Output is correct |
16 |
Correct |
8 ms |
1876 KB |
Output is correct |
17 |
Correct |
9 ms |
1876 KB |
Output is correct |
18 |
Correct |
9 ms |
1876 KB |
Output is correct |
19 |
Correct |
8 ms |
1876 KB |
Output is correct |
20 |
Correct |
10 ms |
1876 KB |
Output is correct |
21 |
Correct |
69 ms |
1876 KB |
Output is correct |
22 |
Correct |
70 ms |
1876 KB |
Output is correct |
23 |
Correct |
72 ms |
1876 KB |
Output is correct |
24 |
Correct |
73 ms |
1876 KB |
Output is correct |
25 |
Correct |
67 ms |
1876 KB |
Output is correct |
26 |
Correct |
67 ms |
1876 KB |
Output is correct |
27 |
Correct |
69 ms |
1876 KB |
Output is correct |
28 |
Correct |
67 ms |
1876 KB |
Output is correct |
29 |
Correct |
66 ms |
1876 KB |
Output is correct |
30 |
Correct |
59 ms |
1876 KB |
Output is correct |
31 |
Correct |
61 ms |
1876 KB |
Output is correct |
32 |
Correct |
61 ms |
1876 KB |
Output is correct |
33 |
Correct |
60 ms |
1876 KB |
Output is correct |
34 |
Correct |
59 ms |
1876 KB |
Output is correct |
35 |
Correct |
60 ms |
1916 KB |
Output is correct |
36 |
Correct |
60 ms |
1916 KB |
Output is correct |
37 |
Correct |
56 ms |
1916 KB |
Output is correct |
38 |
Correct |
57 ms |
1916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1916 KB |
Output is correct |
2 |
Correct |
16 ms |
1916 KB |
Output is correct |
3 |
Correct |
19 ms |
1916 KB |
Output is correct |
4 |
Correct |
21 ms |
1916 KB |
Output is correct |
5 |
Correct |
18 ms |
1916 KB |
Output is correct |
6 |
Correct |
32 ms |
1916 KB |
Output is correct |
7 |
Correct |
23 ms |
1916 KB |
Output is correct |
8 |
Correct |
24 ms |
1916 KB |
Output is correct |
9 |
Correct |
23 ms |
1916 KB |
Output is correct |
10 |
Correct |
24 ms |
1916 KB |
Output is correct |
11 |
Correct |
23 ms |
1916 KB |
Output is correct |
12 |
Correct |
21 ms |
1916 KB |
Output is correct |
13 |
Correct |
17 ms |
1916 KB |
Output is correct |
14 |
Correct |
17 ms |
1916 KB |
Output is correct |
15 |
Correct |
23 ms |
1916 KB |
Output is correct |
16 |
Correct |
11 ms |
1916 KB |
Output is correct |
17 |
Correct |
10 ms |
1916 KB |
Output is correct |
18 |
Correct |
10 ms |
1916 KB |
Output is correct |
19 |
Correct |
10 ms |
1916 KB |
Output is correct |
20 |
Correct |
13 ms |
1916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
1528 KB |
Output is correct |
2 |
Correct |
33 ms |
1640 KB |
Output is correct |
3 |
Correct |
35 ms |
1844 KB |
Output is correct |
4 |
Correct |
34 ms |
1844 KB |
Output is correct |
5 |
Correct |
34 ms |
1844 KB |
Output is correct |
6 |
Correct |
32 ms |
1876 KB |
Output is correct |
7 |
Correct |
33 ms |
1876 KB |
Output is correct |
8 |
Correct |
31 ms |
1876 KB |
Output is correct |
9 |
Correct |
34 ms |
1876 KB |
Output is correct |
10 |
Correct |
32 ms |
1876 KB |
Output is correct |
11 |
Correct |
34 ms |
1876 KB |
Output is correct |
12 |
Correct |
35 ms |
1876 KB |
Output is correct |
13 |
Correct |
31 ms |
1876 KB |
Output is correct |
14 |
Correct |
30 ms |
1876 KB |
Output is correct |
15 |
Correct |
32 ms |
1876 KB |
Output is correct |
16 |
Correct |
8 ms |
1876 KB |
Output is correct |
17 |
Correct |
9 ms |
1876 KB |
Output is correct |
18 |
Correct |
9 ms |
1876 KB |
Output is correct |
19 |
Correct |
8 ms |
1876 KB |
Output is correct |
20 |
Correct |
10 ms |
1876 KB |
Output is correct |
21 |
Correct |
69 ms |
1876 KB |
Output is correct |
22 |
Correct |
70 ms |
1876 KB |
Output is correct |
23 |
Correct |
72 ms |
1876 KB |
Output is correct |
24 |
Correct |
73 ms |
1876 KB |
Output is correct |
25 |
Correct |
67 ms |
1876 KB |
Output is correct |
26 |
Correct |
67 ms |
1876 KB |
Output is correct |
27 |
Correct |
69 ms |
1876 KB |
Output is correct |
28 |
Correct |
67 ms |
1876 KB |
Output is correct |
29 |
Correct |
66 ms |
1876 KB |
Output is correct |
30 |
Correct |
59 ms |
1876 KB |
Output is correct |
31 |
Correct |
61 ms |
1876 KB |
Output is correct |
32 |
Correct |
61 ms |
1876 KB |
Output is correct |
33 |
Correct |
60 ms |
1876 KB |
Output is correct |
34 |
Correct |
59 ms |
1876 KB |
Output is correct |
35 |
Correct |
60 ms |
1916 KB |
Output is correct |
36 |
Correct |
60 ms |
1916 KB |
Output is correct |
37 |
Correct |
56 ms |
1916 KB |
Output is correct |
38 |
Correct |
57 ms |
1916 KB |
Output is correct |
39 |
Correct |
18 ms |
1916 KB |
Output is correct |
40 |
Correct |
16 ms |
1916 KB |
Output is correct |
41 |
Correct |
19 ms |
1916 KB |
Output is correct |
42 |
Correct |
21 ms |
1916 KB |
Output is correct |
43 |
Correct |
18 ms |
1916 KB |
Output is correct |
44 |
Correct |
32 ms |
1916 KB |
Output is correct |
45 |
Correct |
23 ms |
1916 KB |
Output is correct |
46 |
Correct |
24 ms |
1916 KB |
Output is correct |
47 |
Correct |
23 ms |
1916 KB |
Output is correct |
48 |
Correct |
24 ms |
1916 KB |
Output is correct |
49 |
Correct |
23 ms |
1916 KB |
Output is correct |
50 |
Correct |
21 ms |
1916 KB |
Output is correct |
51 |
Correct |
17 ms |
1916 KB |
Output is correct |
52 |
Correct |
17 ms |
1916 KB |
Output is correct |
53 |
Correct |
23 ms |
1916 KB |
Output is correct |
54 |
Correct |
11 ms |
1916 KB |
Output is correct |
55 |
Correct |
10 ms |
1916 KB |
Output is correct |
56 |
Correct |
10 ms |
1916 KB |
Output is correct |
57 |
Correct |
10 ms |
1916 KB |
Output is correct |
58 |
Correct |
13 ms |
1916 KB |
Output is correct |
59 |
Correct |
617 ms |
2196 KB |
Output is correct |
60 |
Correct |
632 ms |
2196 KB |
Output is correct |
61 |
Correct |
560 ms |
2196 KB |
Output is correct |
62 |
Correct |
656 ms |
2196 KB |
Output is correct |
63 |
Correct |
569 ms |
2196 KB |
Output is correct |
64 |
Correct |
1503 ms |
2196 KB |
Output is correct |
65 |
Correct |
1426 ms |
2196 KB |
Output is correct |
66 |
Correct |
1299 ms |
2196 KB |
Output is correct |
67 |
Correct |
1321 ms |
2196 KB |
Output is correct |
68 |
Correct |
1359 ms |
2196 KB |
Output is correct |
69 |
Correct |
485 ms |
2196 KB |
Output is correct |
70 |
Correct |
525 ms |
2196 KB |
Output is correct |
71 |
Correct |
675 ms |
2196 KB |
Output is correct |
72 |
Correct |
820 ms |
2196 KB |
Output is correct |
73 |
Correct |
698 ms |
2196 KB |
Output is correct |
74 |
Correct |
80 ms |
2196 KB |
Output is correct |
75 |
Correct |
61 ms |
2196 KB |
Output is correct |
76 |
Correct |
63 ms |
2196 KB |
Output is correct |
77 |
Correct |
63 ms |
2196 KB |
Output is correct |
78 |
Correct |
91 ms |
2196 KB |
Output is correct |