# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
268694 |
2020-08-16T18:37:38 Z |
test2 |
Boat (APIO16_boat) |
C++14 |
|
623 ms |
33784 KB |
#include<bits/stdc++.h>
#define I inline void
using ll = long long ;
using ld = long double ;
using namespace std ;
const int N = 2000 + 7 , mod = 1e9 + 7 ;
// how interesting!
int n;
ll ans ;
map<int , int > used ;
vector<pair<int , int> > st ;
vector<pair<int , int> > v ;
I add(int u , int v){
while(u <=v && used[u])u++ ;
while(v>=u&&used[v])v-- ;
if(u <=v){
st.push_back({u , v}) ;
}
}
vector<int> onepiece[N] ;
ll dp[N][N] ;
ll solve(int i , int j){
if(dp[i][j]!=-1)
return dp[i][j] ;
if(i == (int) st.size())
return 1;
ll ret = solve(i+1 , j ) ;
for(auto u : onepiece[i]){
if(u > j){
ret = (ret + solve(i+1 , u) * (st[i].second - st[i].first + 1ll ) %mod ) %mod ;
}
}
return dp[i][j] = ret ;
}
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
memset(dp , -1 , sizeof dp) ;
//freopen("in.in" , "r" , stdin) ;
cin >> n;
set<int> ev ;
for(int i = 0 ;i < n;i++){
int x , y ;
cin >> x >> y ;
ev.insert(x) ;
ev.insert(y) ;
used[x] = used[y] = 1;
st.push_back({x , x}) ;
st.push_back({y , y}) ;
v.push_back({x , y}) ;
}
int l = 0 ;
for(auto u : ev){
if(l){
add(l+1 , u - 1) ;
}
l = u ;
}
sort(st.begin() , st.end()) ;
st.resize( unique(st.begin() , st.end()) - st.begin()) ;
for(int i = 0 ;i < (int) st.size() ; i++){
for(int j = 0 ;j < n; j++){
if( st[i].first>= v[j].first && st[i].second <= v[j].second ){
onepiece[i].push_back(j + 1) ;
}
}
}
for(int i = 1 ;i < (int) st.size() ;i ++){
assert( st[i].first > st[i-1].second ) ;
assert(st[i].first <= st[i].second) ;
}
cout<< (mod + solve(0 , 0 ) -1 ) %mod ;
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
32128 KB |
Output is correct |
2 |
Correct |
27 ms |
32120 KB |
Output is correct |
3 |
Correct |
25 ms |
32128 KB |
Output is correct |
4 |
Correct |
24 ms |
32128 KB |
Output is correct |
5 |
Correct |
25 ms |
32128 KB |
Output is correct |
6 |
Correct |
25 ms |
32128 KB |
Output is correct |
7 |
Correct |
25 ms |
32128 KB |
Output is correct |
8 |
Correct |
26 ms |
32128 KB |
Output is correct |
9 |
Correct |
25 ms |
32128 KB |
Output is correct |
10 |
Correct |
26 ms |
32256 KB |
Output is correct |
11 |
Correct |
25 ms |
32128 KB |
Output is correct |
12 |
Correct |
25 ms |
32128 KB |
Output is correct |
13 |
Correct |
29 ms |
32120 KB |
Output is correct |
14 |
Correct |
25 ms |
32128 KB |
Output is correct |
15 |
Correct |
29 ms |
32128 KB |
Output is correct |
16 |
Correct |
23 ms |
32000 KB |
Output is correct |
17 |
Correct |
20 ms |
32000 KB |
Output is correct |
18 |
Correct |
22 ms |
32000 KB |
Output is correct |
19 |
Correct |
23 ms |
32000 KB |
Output is correct |
20 |
Correct |
20 ms |
32000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
32128 KB |
Output is correct |
2 |
Correct |
27 ms |
32120 KB |
Output is correct |
3 |
Correct |
25 ms |
32128 KB |
Output is correct |
4 |
Correct |
24 ms |
32128 KB |
Output is correct |
5 |
Correct |
25 ms |
32128 KB |
Output is correct |
6 |
Correct |
25 ms |
32128 KB |
Output is correct |
7 |
Correct |
25 ms |
32128 KB |
Output is correct |
8 |
Correct |
26 ms |
32128 KB |
Output is correct |
9 |
Correct |
25 ms |
32128 KB |
Output is correct |
10 |
Correct |
26 ms |
32256 KB |
Output is correct |
11 |
Correct |
25 ms |
32128 KB |
Output is correct |
12 |
Correct |
25 ms |
32128 KB |
Output is correct |
13 |
Correct |
29 ms |
32120 KB |
Output is correct |
14 |
Correct |
25 ms |
32128 KB |
Output is correct |
15 |
Correct |
29 ms |
32128 KB |
Output is correct |
16 |
Correct |
23 ms |
32000 KB |
Output is correct |
17 |
Correct |
20 ms |
32000 KB |
Output is correct |
18 |
Correct |
22 ms |
32000 KB |
Output is correct |
19 |
Correct |
23 ms |
32000 KB |
Output is correct |
20 |
Correct |
20 ms |
32000 KB |
Output is correct |
21 |
Incorrect |
623 ms |
33784 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
32128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
32128 KB |
Output is correct |
2 |
Correct |
27 ms |
32120 KB |
Output is correct |
3 |
Correct |
25 ms |
32128 KB |
Output is correct |
4 |
Correct |
24 ms |
32128 KB |
Output is correct |
5 |
Correct |
25 ms |
32128 KB |
Output is correct |
6 |
Correct |
25 ms |
32128 KB |
Output is correct |
7 |
Correct |
25 ms |
32128 KB |
Output is correct |
8 |
Correct |
26 ms |
32128 KB |
Output is correct |
9 |
Correct |
25 ms |
32128 KB |
Output is correct |
10 |
Correct |
26 ms |
32256 KB |
Output is correct |
11 |
Correct |
25 ms |
32128 KB |
Output is correct |
12 |
Correct |
25 ms |
32128 KB |
Output is correct |
13 |
Correct |
29 ms |
32120 KB |
Output is correct |
14 |
Correct |
25 ms |
32128 KB |
Output is correct |
15 |
Correct |
29 ms |
32128 KB |
Output is correct |
16 |
Correct |
23 ms |
32000 KB |
Output is correct |
17 |
Correct |
20 ms |
32000 KB |
Output is correct |
18 |
Correct |
22 ms |
32000 KB |
Output is correct |
19 |
Correct |
23 ms |
32000 KB |
Output is correct |
20 |
Correct |
20 ms |
32000 KB |
Output is correct |
21 |
Incorrect |
623 ms |
33784 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |