# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
970709 | VinhLuu | Boat (APIO16_boat) | C++17 | 491 ms | 8792 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1005;
int block = 555;
const int mod = 1e9 + 7;
//const ll oo = 5e18;
int n, L[N], R[N];
ll f[N][N], inv[N];
ll lt(ll u,ll v){
if(v == 0) return 1;
ll x = u, kq = 1;
while(v){
if(v & 1) kq = kq * x % mod;
x = x * x % mod;
v /= 2;
}
return kq;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n;
vector<int> rrh;
for(int i = 1; i <= n; i ++){
cin >> L[i] >> R[i];
rrh.pb(L[i]);
rrh.pb(R[i] + 1);
}
sort(all(rrh)); rrh.resize(unique(all(rrh)) - rrh.begin());
inv[0] = f[0][0] = 1;
for(int i = 1; i <= n + 1; i ++) inv[i] = lt(i, mod - 2);
for(int i = 1; i < rrh.size(); i ++){
// cerr << i << " h\n";
f[i][0] = 1;
for(int j = 1; j <= n; j ++) if(L[j] <= rrh[i - 1] && rrh[i - 1] <= R[j]){
f[i][j] = f[i - 1][j];
ll w = rrh[i] - rrh[i - 1], pick = 1, cnt = 0;
// cerr << i << " " << j << " " << f[i][j] << " j\n";
for(int k = 1; k <= j; k ++){
if(L[j - k + 1] <= rrh[i - 1] && rrh[i - 1] <= R[j - k + 1]){
// if(cnt + 1 <= w){
cnt++;
pick = pick * (w + cnt - 1) % mod * inv[cnt] % mod;
// if(cnt == 1) pick = pick * (w - cnt + 1) % mod * inv[cnt] % mod;
// else pick = (pick + pick * (w - cnt + 1) % mod * inv[cnt] % mod) % mod;
// }else pick = (pick + 0ll * cnt * pick % mod) % mod;
// cerr << i << " " << w << " " << k << " " << j - k << " " << pick << " " << f[i - 1][j - k] << " g\n";
f[i][j] = (f[i][j] + f[i - 1][j - k] * pick % mod) % mod;
}else{
f[i][j] = (f[i][j] + f[i - 1][j - k] * pick % mod) % mod;
}
}
// cerr << i << " " << j << " " << f[i][j] << " k\n";
}else{
f[i][j] = f[i - 1][j];
// cerr << i << " " << j << " " << f[i][j] << " k\n";
}
}
ll ans = 0;
for(int i = 1; i <= n; i ++) ans = (ans + f[rrh.size() - 1][i]) % mod;
cout << ans;
}
컴파일 시 표준 에러 (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... |