# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47972 | 2018-05-09T09:40:42 Z | 3zp | Boat (APIO16_boat) | C++14 | 43 ms | 9440 KB |
#include<bits/stdc++.h> #define ll long long using namespace std; ll a[5009], b[5009]; ll mod = 1e9+7; ll c[2009]; ll l[5009], r[5009]; ll dp[5009][4009]; ll in[5009]; vector<pair<ll,ll> > d; main(){ ll n; cin >> n; for(ll i = 0; i < n; i++){ cin >> a[i] >> b[i]; c[2*i] = a[i]; c[2*i + 1] = b[i]; } sort(c, c+2*n); in[0] = 1; in[1] = 1; for (int i = 2; i <= n; i++) in[i] = in[mod % i] *(mod - mod / i) % mod; for(ll i = 0; i < 2*n; i++){ if(i < 2*n-1 && c[i] == c[i+1]) continue; d.push_back({c[i], c[i]}); if(i == 2*n-1 || c[i+1] == c[i]+1) continue; d.push_back({c[i]+1, c[i+1]-1}); } for (ll i= 0; i < n; i++){ for (ll j = 0; j < d.size(); j++){ if(a[i] == d[j].first) {l[i] = j; break;} } for (ll j = 0; j < d.size(); j++){ if(b[i] == d[j].second) r[i] = j; } } ll N = d.size(); for(ll i = 0; i < n; i++){ for(ll j = 0; j < N; j++){ if(j) dp[i][j] = (dp[i][j-1]); ll L = d[j].second - d[j].first + 1; ll W = 1; for (ll t = i; t >= 0; t--){ if(l[t] > j || r[t] < j) break; W = W*(L - (i -t)) % mod *in[i-t+1] % mod; if(t == 0) dp[i][j] = (dp[i][j] + W) % mod; else if(j == 0) dp[i][j] = (dp[i][j] + W) % mod; else dp[i][j] = (dp[i][j] + W*dp[t-1][j-1]) % mod; } } for(ll j = 0; j < N; j++){ if(i) dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod; else dp[i][j] = (dp[i][j] + 1) % mod; } } cout << (dp[n-1][N-1] -1 + mod)% mod << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 6264 KB | Output is correct |
2 | Correct | 15 ms | 6372 KB | Output is correct |
3 | Correct | 15 ms | 6588 KB | Output is correct |
4 | Correct | 15 ms | 6588 KB | Output is correct |
5 | Correct | 15 ms | 6588 KB | Output is correct |
6 | Correct | 15 ms | 6588 KB | Output is correct |
7 | Correct | 15 ms | 6588 KB | Output is correct |
8 | Correct | 15 ms | 6588 KB | Output is correct |
9 | Correct | 15 ms | 6588 KB | Output is correct |
10 | Correct | 15 ms | 6676 KB | Output is correct |
11 | Correct | 15 ms | 6704 KB | Output is correct |
12 | Correct | 15 ms | 6704 KB | Output is correct |
13 | Correct | 14 ms | 6704 KB | Output is correct |
14 | Correct | 15 ms | 6704 KB | Output is correct |
15 | Correct | 16 ms | 6784 KB | Output is correct |
16 | Correct | 7 ms | 6784 KB | Output is correct |
17 | Correct | 6 ms | 6784 KB | Output is correct |
18 | Correct | 6 ms | 6784 KB | Output is correct |
19 | Correct | 6 ms | 6784 KB | Output is correct |
20 | Correct | 7 ms | 6784 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 6264 KB | Output is correct |
2 | Correct | 15 ms | 6372 KB | Output is correct |
3 | Correct | 15 ms | 6588 KB | Output is correct |
4 | Correct | 15 ms | 6588 KB | Output is correct |
5 | Correct | 15 ms | 6588 KB | Output is correct |
6 | Correct | 15 ms | 6588 KB | Output is correct |
7 | Correct | 15 ms | 6588 KB | Output is correct |
8 | Correct | 15 ms | 6588 KB | Output is correct |
9 | Correct | 15 ms | 6588 KB | Output is correct |
10 | Correct | 15 ms | 6676 KB | Output is correct |
11 | Correct | 15 ms | 6704 KB | Output is correct |
12 | Correct | 15 ms | 6704 KB | Output is correct |
13 | Correct | 14 ms | 6704 KB | Output is correct |
14 | Correct | 15 ms | 6704 KB | Output is correct |
15 | Correct | 16 ms | 6784 KB | Output is correct |
16 | Correct | 7 ms | 6784 KB | Output is correct |
17 | Correct | 6 ms | 6784 KB | Output is correct |
18 | Correct | 6 ms | 6784 KB | Output is correct |
19 | Correct | 6 ms | 6784 KB | Output is correct |
20 | Correct | 7 ms | 6784 KB | Output is correct |
21 | Incorrect | 43 ms | 9440 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 9440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 6264 KB | Output is correct |
2 | Correct | 15 ms | 6372 KB | Output is correct |
3 | Correct | 15 ms | 6588 KB | Output is correct |
4 | Correct | 15 ms | 6588 KB | Output is correct |
5 | Correct | 15 ms | 6588 KB | Output is correct |
6 | Correct | 15 ms | 6588 KB | Output is correct |
7 | Correct | 15 ms | 6588 KB | Output is correct |
8 | Correct | 15 ms | 6588 KB | Output is correct |
9 | Correct | 15 ms | 6588 KB | Output is correct |
10 | Correct | 15 ms | 6676 KB | Output is correct |
11 | Correct | 15 ms | 6704 KB | Output is correct |
12 | Correct | 15 ms | 6704 KB | Output is correct |
13 | Correct | 14 ms | 6704 KB | Output is correct |
14 | Correct | 15 ms | 6704 KB | Output is correct |
15 | Correct | 16 ms | 6784 KB | Output is correct |
16 | Correct | 7 ms | 6784 KB | Output is correct |
17 | Correct | 6 ms | 6784 KB | Output is correct |
18 | Correct | 6 ms | 6784 KB | Output is correct |
19 | Correct | 6 ms | 6784 KB | Output is correct |
20 | Correct | 7 ms | 6784 KB | Output is correct |
21 | Incorrect | 43 ms | 9440 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |