# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
399980 |
2021-05-07T02:37:46 Z |
jeqcho |
Boat (APIO16_boat) |
C++17 |
|
9 ms |
4372 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
// subtask 1 and 2
int const N=5e2+3;
ll a[N],b[N];
ll dp[N][2*N];
ll mod =1e9+7;
ll aps(ll n, ll d)
{
return n * (((ll)2 + (n-(ll)1)*d)%mod) / (ll)2;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin>>n;
set<ll> st;
F0R(i,n)
{
cin>>a[i]>>b[i];
--a[i];
st.insert(a[i]);
st.insert(b[i]);
}
st.insert(0);
vi v(all(st));
map<ll,ll>mp;
F0R(i,sz(st))
{
mp[v[i]]=i;
}
F0R(i,n)
{
a[i]=mp[a[i]];
b[i]=mp[b[i]];
}
F0R(j,sz(st)+1)
{
dp[0][j]=1;
}
dp[0][0]=0;
F0R(i,n)
{
F0R(j,sz(st))
{
dp[i+1][j+1]=dp[i][j+1]-dp[i][j];
dp[i+1][j+1]+=mod;
dp[i+1][j+1]%=mod;
}
FOR(j,a[i]+1,b[i]+1)
{
ll l = v[j]-v[j-1];
F0R(k,l)
{
ll add = aps(l-k,k) * dp[i-k][j];
add%=mod;
dp[i+1][j+1]+=add;
dp[i+1][j+1]%=mod;
}
}
F0R(j,sz(st))
{
dp[i+1][j+1]+=dp[i+1][j];
dp[i+1][j+1]%=mod;
}
}
ll ans=dp[n][sz(st)]-1;
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4300 KB |
Output is correct |
4 |
Correct |
8 ms |
4300 KB |
Output is correct |
5 |
Correct |
9 ms |
4364 KB |
Output is correct |
6 |
Correct |
8 ms |
4296 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
8 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4316 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
8 ms |
4372 KB |
Output is correct |
15 |
Correct |
8 ms |
4300 KB |
Output is correct |
16 |
Correct |
4 ms |
3020 KB |
Output is correct |
17 |
Correct |
3 ms |
3020 KB |
Output is correct |
18 |
Correct |
3 ms |
3020 KB |
Output is correct |
19 |
Correct |
3 ms |
3020 KB |
Output is correct |
20 |
Correct |
3 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4300 KB |
Output is correct |
4 |
Correct |
8 ms |
4300 KB |
Output is correct |
5 |
Correct |
9 ms |
4364 KB |
Output is correct |
6 |
Correct |
8 ms |
4296 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
8 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4316 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
8 ms |
4372 KB |
Output is correct |
15 |
Correct |
8 ms |
4300 KB |
Output is correct |
16 |
Correct |
4 ms |
3020 KB |
Output is correct |
17 |
Correct |
3 ms |
3020 KB |
Output is correct |
18 |
Correct |
3 ms |
3020 KB |
Output is correct |
19 |
Correct |
3 ms |
3020 KB |
Output is correct |
20 |
Correct |
3 ms |
3020 KB |
Output is correct |
21 |
Runtime error |
2 ms |
720 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4300 KB |
Output is correct |
2 |
Correct |
8 ms |
4300 KB |
Output is correct |
3 |
Correct |
8 ms |
4300 KB |
Output is correct |
4 |
Correct |
8 ms |
4300 KB |
Output is correct |
5 |
Correct |
9 ms |
4364 KB |
Output is correct |
6 |
Correct |
8 ms |
4296 KB |
Output is correct |
7 |
Correct |
8 ms |
4300 KB |
Output is correct |
8 |
Correct |
8 ms |
4300 KB |
Output is correct |
9 |
Correct |
8 ms |
4300 KB |
Output is correct |
10 |
Correct |
8 ms |
4300 KB |
Output is correct |
11 |
Correct |
8 ms |
4300 KB |
Output is correct |
12 |
Correct |
8 ms |
4316 KB |
Output is correct |
13 |
Correct |
8 ms |
4300 KB |
Output is correct |
14 |
Correct |
8 ms |
4372 KB |
Output is correct |
15 |
Correct |
8 ms |
4300 KB |
Output is correct |
16 |
Correct |
4 ms |
3020 KB |
Output is correct |
17 |
Correct |
3 ms |
3020 KB |
Output is correct |
18 |
Correct |
3 ms |
3020 KB |
Output is correct |
19 |
Correct |
3 ms |
3020 KB |
Output is correct |
20 |
Correct |
3 ms |
3020 KB |
Output is correct |
21 |
Runtime error |
2 ms |
720 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |