# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
152794 | 2019-09-09T14:12:05 Z | mhy908 | Boat (APIO16_boat) | C++14 | 10 ms | 2296 KB |
#include <bits/stdc++.h> #define pb push_back #define all(x) x.begin(), x.end() #define llinf 8987654321987654321 #define mod 1000000007 using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; vector<LL> id; int n; LL a[510], b[510]; LL dp[510][510], sum[510][510], inv[510], len[1010]; LL power(LL a, LL b) { if(!b)return 1; LL ret=power(a, b/2); return b%2?ret*ret%mod*a%mod:ret*ret%mod; } int main() { scanf("%d", &n); for(int i=1; i<=n; i++)inv[i]=power(i, mod-2); for(int i=1; i<=n; i++){ scanf("%lld %lld", &a[i], &b[i]); id.pb(a[i]-1); id.pb(b[i]); } sort(all(id)); id.erase(unique(all(id)), id.end()); for(int i=1; i<=n; i++){ LL temp=lower_bound(all(id), a[i]-1)+1-id.begin(); a[i]=temp; temp=lower_bound(all(id), b[i])+1-id.begin(); b[i]=temp; } int siz=id.size(); len[1]=id[0]; for(int i=1; i<=siz; i++)len[i]=id[i-1]-id[i-2]; for(int i=1;i<=n;i++){ for(int j=1; j<=siz; j++){ if(i==1&&a[i]<j&&j<=b[i])dp[i][j]=(dp[i][j]+len[j])%mod; else{ if(a[i]<j&&j<=b[i]){ dp[i][j]=(dp[i][j]+len[j]*(1+dp[i-1][j-1]))%mod; int cnt=1; LL sum=len[j]-1; for(int k=i-1; k>=1; k--){ if(a[k]<j&&j<=b[k]){ cnt++; sum=sum*(len[j]+cnt-2)%mod*inv[cnt]%mod; dp[i][j]=(dp[i][j]+sum+sum*dp[k-1][j-1])%mod; } } } } dp[i][j]=(dp[i][j]+dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+mod)%mod; } } printf("%lld", dp[n][siz]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 2296 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 2296 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 760 KB | Output is correct |
2 | Correct | 4 ms | 632 KB | Output is correct |
3 | Correct | 5 ms | 760 KB | Output is correct |
4 | Correct | 5 ms | 680 KB | Output is correct |
5 | Correct | 5 ms | 760 KB | Output is correct |
6 | Correct | 7 ms | 760 KB | Output is correct |
7 | Correct | 8 ms | 760 KB | Output is correct |
8 | Correct | 8 ms | 760 KB | Output is correct |
9 | Correct | 8 ms | 760 KB | Output is correct |
10 | Correct | 8 ms | 760 KB | Output is correct |
11 | Correct | 5 ms | 760 KB | Output is correct |
12 | Correct | 4 ms | 760 KB | Output is correct |
13 | Correct | 5 ms | 732 KB | Output is correct |
14 | Correct | 5 ms | 764 KB | Output is correct |
15 | Correct | 6 ms | 760 KB | Output is correct |
16 | Correct | 5 ms | 760 KB | Output is correct |
17 | Correct | 4 ms | 760 KB | Output is correct |
18 | Correct | 4 ms | 760 KB | Output is correct |
19 | Correct | 4 ms | 760 KB | Output is correct |
20 | Correct | 4 ms | 760 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 2296 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |