# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
145305 | 2019-08-19T14:48:23 Z | arnold518 | Boat (APIO16_boat) | C++14 | 48 ms | 8316 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 500; const ll MOD = 1e9+7; int N, A[MAXN+10], B[MAXN+10]; vector<int> comp; ll dp[MAXN+10][MAXN*2+10], psum[MAXN+10][MAXN*2+10], cnt[MAXN*2+10], val[MAXN*2+10]; int getcomp(int x) { return lower_bound(comp.begin(), comp.end(), x)-comp.begin()+1; } ll mypow(ll x, ll y) { if(y==0) return 1; if(y%2) return mypow(x, y-1)*x%MOD; ll ret=mypow(x, y/2); return ret*ret%MOD; } ll inv(ll x) { return mypow(x, MOD-2); } ll comb(ll n, ll r) { ll i, j; r=min(r, n-r); ll ret=1; for(i=1; i<=r; i++) ret=ret*inv(i)%MOD*(n-i+1)%MOD; return ret; } ll f(ll i, ll j) { return comb(i+j-1, i); } int main() { int i, j; scanf("%d", &N); for(i=1; i<=N; i++) scanf("%d%d", &A[i], &B[i]), B[i]++, comp.push_back(A[i]), comp.push_back(B[i]); sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); dp[0][0]=1; for(j=0; j<comp.size(); j++) psum[0][j]=1; for(i=1; i<=N; i++) { for(j=0; j<comp.size(); j++) { if(!(getcomp(A[i])<=j && j<getcomp(B[i]))) { dp[i][j]=dp[i-1][j]; continue; } cnt[j]++; if(cnt[j]==1) { val[j]=psum[i-1][j-1]; dp[i][j]+=psum[i-1][j-1]*(comp[j]-comp[j-1])%MOD; } else { dp[i][j]+=(psum[i-1][j-1]*(comp[j]-comp[j-1])%MOD+val[j]*f(cnt[j], comp[j]-comp[j-1])%MOD)%MOD; } dp[i][j]%=MOD; } psum[i][0]=dp[i][0]; for(j=1; j<comp.size(); j++) psum[i][j]=(dp[i][j]+psum[i][j-1])%MOD; } printf("%lld", (psum[N][comp.size()-1]+MOD-1)%MOD); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 8312 KB | Output is correct |
2 | Correct | 25 ms | 8312 KB | Output is correct |
3 | Correct | 25 ms | 8284 KB | Output is correct |
4 | Correct | 28 ms | 8312 KB | Output is correct |
5 | Correct | 28 ms | 8312 KB | Output is correct |
6 | Correct | 25 ms | 8312 KB | Output is correct |
7 | Correct | 29 ms | 8312 KB | Output is correct |
8 | Correct | 25 ms | 8312 KB | Output is correct |
9 | Correct | 25 ms | 8312 KB | Output is correct |
10 | Correct | 25 ms | 8316 KB | Output is correct |
11 | Correct | 25 ms | 8316 KB | Output is correct |
12 | Correct | 25 ms | 8316 KB | Output is correct |
13 | Correct | 25 ms | 8312 KB | Output is correct |
14 | Correct | 25 ms | 8248 KB | Output is correct |
15 | Correct | 25 ms | 8260 KB | Output is correct |
16 | Incorrect | 9 ms | 5752 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 8312 KB | Output is correct |
2 | Correct | 25 ms | 8312 KB | Output is correct |
3 | Correct | 25 ms | 8284 KB | Output is correct |
4 | Correct | 28 ms | 8312 KB | Output is correct |
5 | Correct | 28 ms | 8312 KB | Output is correct |
6 | Correct | 25 ms | 8312 KB | Output is correct |
7 | Correct | 29 ms | 8312 KB | Output is correct |
8 | Correct | 25 ms | 8312 KB | Output is correct |
9 | Correct | 25 ms | 8312 KB | Output is correct |
10 | Correct | 25 ms | 8316 KB | Output is correct |
11 | Correct | 25 ms | 8316 KB | Output is correct |
12 | Correct | 25 ms | 8316 KB | Output is correct |
13 | Correct | 25 ms | 8312 KB | Output is correct |
14 | Correct | 25 ms | 8248 KB | Output is correct |
15 | Correct | 25 ms | 8260 KB | Output is correct |
16 | Incorrect | 9 ms | 5752 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 48 ms | 1568 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 8312 KB | Output is correct |
2 | Correct | 25 ms | 8312 KB | Output is correct |
3 | Correct | 25 ms | 8284 KB | Output is correct |
4 | Correct | 28 ms | 8312 KB | Output is correct |
5 | Correct | 28 ms | 8312 KB | Output is correct |
6 | Correct | 25 ms | 8312 KB | Output is correct |
7 | Correct | 29 ms | 8312 KB | Output is correct |
8 | Correct | 25 ms | 8312 KB | Output is correct |
9 | Correct | 25 ms | 8312 KB | Output is correct |
10 | Correct | 25 ms | 8316 KB | Output is correct |
11 | Correct | 25 ms | 8316 KB | Output is correct |
12 | Correct | 25 ms | 8316 KB | Output is correct |
13 | Correct | 25 ms | 8312 KB | Output is correct |
14 | Correct | 25 ms | 8248 KB | Output is correct |
15 | Correct | 25 ms | 8260 KB | Output is correct |
16 | Incorrect | 9 ms | 5752 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |