# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199231 | anachor | Boat (APIO16_boat) | C++14 | 374 ms | 16248 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 1005, M = 1e9+7;
int l[N], r[N];
int st[N], len[N];
typedef long long LL;
LL dp[N][N];
LL sum[N][N];
LL power(LL a, LL p) {
if (p==0) return 1;
LL ans = power(a, p/2);
ans = (ans * ans)%M;
if (p%2) ans = (ans * a)%M;
return ans;
}
LL f[N][N];
LL inv[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
map<int, int> mp;
for (int i=1; i<=n; i++) {
cin>>l[i]>>r[i];
mp[l[i]] = mp[r[i]+1] = 0;
}
int sz = 0;
for (auto &pr: mp) {
pr.second = ++sz;
st[sz] = pr.first;
}
for (int i=1; i<=n; i++) inv[i] = power(i, M-2);
for (int i=1; i<sz; i++) {
len[i] = st[i+1] - st[i];
f[i][0] = 1;
for (int j=1; j<=n; j++) {
f[i][j] = (f[i][j-1]*(len[i]+j-1))%M;
f[i][j] = (f[i][j]*inv[j])%M;
}
}
dp[0][0] = 1;
for (int i=0; i<=sz; i++) sum[0][i] = 1;
long long ans = 0;
for (int i=1; i<=n; i++) {
int ll = mp[l[i]], rr = mp[r[i]+1];
for (int k=1; k<=sz; k++) {
if (!(l[i] <= st[k] && st[k] <= r[i])) continue;
int pos = 0;
for (int j=i; j>=1; j--) {
if (l[j] <= st[k] && st[k] <= r[j]) pos++;
dp[i][k] = (dp[i][k] + f[k][pos] * sum[j-1][k-1])%M;
}
}
for (int k=1; k<=sz; k++)
sum[i][k] = (sum[i][k-1] + dp[i][k])%M;
ans = (ans + sum[i][sz])%M;
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |