# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
184089 | 2020-01-10T13:03:09 Z | dndhk | Boat (APIO16_boat) | C++14 | 2000 ms | 6536 KB |
#include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() #define sortv(v) sort(all(v)) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define pb push_back #define FI first #define SE second #define lb lower_bound #define ub upper_bound #define test 1 #define TEST if(test) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; const ll MOD = 1000000007; const int INF = 2e9; const ll INFLL = 1e18; const int MAX_N = 500; int N, M; int a[MAX_N+1], b[MAX_N+1]; vector<int> v1; vector<ll> v; map<int, int> mp; void input(){ scanf("%d", &N); for(int i=1 ;i<=N; i++){ scanf("%d%d", &a[i], &b[i]); b[i]++; v1.pb(a[i]); v1.pb(b[i]); } sort(v1.begin(), v1.end()); v1.erase(unique(v1.begin(), v1.end()), v1.end()); sort(v1.begin(), v1.end()); v.pb(1LL); for(int i=0; i<v1.size()-1; i++){ mp[v1[i]] = v.size(); v.pb(v1[i+1]-v1[i]); }mp[v1.back()] = v.size(); for(int i=1; i<=N; i++){ a[i] = mp[a[i]]; b[i] = mp[b[i]]-1; } M = v.size()-1; } ll multi(ll x, ll y){ if(y==0){ return 1LL; }if(y==1){ return x%MOD; } ll m = multi(x, y/2); if(y%2){ return ((m*m%MOD)*x)%MOD; } return (m*m)%MOD; } ll inv[MAX_N+1]; ll dp[MAX_N+1][MAX_N*2+1]; ll dp2[MAX_N+1][MAX_N+1]; void solve(){ for(int i=1; i<=N; i++){ inv[i] = multi((ll)i, MOD-2); } for(int i=0; i<=M; i++) dp[0][i] = 1LL; for(int i=1; i<=N; i++) dp[i][0] = 1LL; for(int k=1; k<=M; k++){ for(int i=1; i<=N; i++){ dp2[i][1] = dp2[i-1][1]; if(a[i]<=k && k<=b[i]) dp2[i][1] = (dp2[i][1] + (dp[i-1][k-1] * v[k] % MOD)) % MOD; dp[i][k]=dp2[i][1]; for(int j=2; j<=N; j++){ dp2[i][j] = 0LL; if(a[i]<=k && k<=b[i]) dp2[i][j] = (dp2[i-1][j-1] * (max(0LL, v[k]-(ll)(j-1)))%MOD) * inv[j] % MOD; dp2[i][j] = (dp2[i][j] + dp2[i-1][j]) % MOD; dp[i][k] = (dp[i][k] + dp2[i][j]) % MOD; } dp[i][k] = (dp[i][k] + dp[i][k-1]) % MOD; } } } int main(){ input(); solve(); cout<<(dp[N][M]+MOD-1) % MOD; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1484 ms | 6428 KB | Output is correct |
2 | Correct | 1483 ms | 6428 KB | Output is correct |
3 | Correct | 1460 ms | 6364 KB | Output is correct |
4 | Correct | 1414 ms | 6392 KB | Output is correct |
5 | Correct | 1413 ms | 6520 KB | Output is correct |
6 | Correct | 1436 ms | 6520 KB | Output is correct |
7 | Correct | 1454 ms | 6520 KB | Output is correct |
8 | Correct | 1398 ms | 6316 KB | Output is correct |
9 | Correct | 1402 ms | 6416 KB | Output is correct |
10 | Correct | 1415 ms | 6340 KB | Output is correct |
11 | Correct | 1389 ms | 6516 KB | Output is correct |
12 | Correct | 1401 ms | 6392 KB | Output is correct |
13 | Correct | 1448 ms | 6448 KB | Output is correct |
14 | Correct | 1437 ms | 6344 KB | Output is correct |
15 | Correct | 1467 ms | 6500 KB | Output is correct |
16 | Correct | 269 ms | 5060 KB | Output is correct |
17 | Correct | 289 ms | 5100 KB | Output is correct |
18 | Correct | 263 ms | 5048 KB | Output is correct |
19 | Correct | 272 ms | 5140 KB | Output is correct |
20 | Correct | 264 ms | 4956 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1484 ms | 6428 KB | Output is correct |
2 | Correct | 1483 ms | 6428 KB | Output is correct |
3 | Correct | 1460 ms | 6364 KB | Output is correct |
4 | Correct | 1414 ms | 6392 KB | Output is correct |
5 | Correct | 1413 ms | 6520 KB | Output is correct |
6 | Correct | 1436 ms | 6520 KB | Output is correct |
7 | Correct | 1454 ms | 6520 KB | Output is correct |
8 | Correct | 1398 ms | 6316 KB | Output is correct |
9 | Correct | 1402 ms | 6416 KB | Output is correct |
10 | Correct | 1415 ms | 6340 KB | Output is correct |
11 | Correct | 1389 ms | 6516 KB | Output is correct |
12 | Correct | 1401 ms | 6392 KB | Output is correct |
13 | Correct | 1448 ms | 6448 KB | Output is correct |
14 | Correct | 1437 ms | 6344 KB | Output is correct |
15 | Correct | 1467 ms | 6500 KB | Output is correct |
16 | Correct | 269 ms | 5060 KB | Output is correct |
17 | Correct | 289 ms | 5100 KB | Output is correct |
18 | Correct | 263 ms | 5048 KB | Output is correct |
19 | Correct | 272 ms | 5140 KB | Output is correct |
20 | Correct | 264 ms | 4956 KB | Output is correct |
21 | Correct | 1786 ms | 6320 KB | Output is correct |
22 | Correct | 1733 ms | 6320 KB | Output is correct |
23 | Correct | 1751 ms | 6328 KB | Output is correct |
24 | Correct | 1835 ms | 6536 KB | Output is correct |
25 | Correct | 1669 ms | 6436 KB | Output is correct |
26 | Correct | 1938 ms | 6300 KB | Output is correct |
27 | Correct | 1938 ms | 6520 KB | Output is correct |
28 | Correct | 1928 ms | 6392 KB | Output is correct |
29 | Correct | 1892 ms | 6404 KB | Output is correct |
30 | Correct | 1423 ms | 6424 KB | Output is correct |
31 | Correct | 1405 ms | 6264 KB | Output is correct |
32 | Correct | 1411 ms | 6520 KB | Output is correct |
33 | Correct | 1778 ms | 6392 KB | Output is correct |
34 | Correct | 1416 ms | 6444 KB | Output is correct |
35 | Correct | 1425 ms | 6480 KB | Output is correct |
36 | Correct | 1458 ms | 6420 KB | Output is correct |
37 | Correct | 1449 ms | 6484 KB | Output is correct |
38 | Correct | 1447 ms | 6520 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 1400 KB | Output is correct |
2 | Correct | 18 ms | 1400 KB | Output is correct |
3 | Correct | 18 ms | 1400 KB | Output is correct |
4 | Correct | 23 ms | 1400 KB | Output is correct |
5 | Correct | 23 ms | 1400 KB | Output is correct |
6 | Correct | 20 ms | 1400 KB | Output is correct |
7 | Correct | 20 ms | 1272 KB | Output is correct |
8 | Correct | 21 ms | 1400 KB | Output is correct |
9 | Correct | 20 ms | 1340 KB | Output is correct |
10 | Correct | 20 ms | 1272 KB | Output is correct |
11 | Correct | 18 ms | 1372 KB | Output is correct |
12 | Correct | 18 ms | 1400 KB | Output is correct |
13 | Correct | 48 ms | 1360 KB | Output is correct |
14 | Correct | 19 ms | 1400 KB | Output is correct |
15 | Correct | 18 ms | 1400 KB | Output is correct |
16 | Correct | 12 ms | 1272 KB | Output is correct |
17 | Correct | 12 ms | 1272 KB | Output is correct |
18 | Correct | 12 ms | 1272 KB | Output is correct |
19 | Correct | 11 ms | 1272 KB | Output is correct |
20 | Correct | 11 ms | 1272 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1484 ms | 6428 KB | Output is correct |
2 | Correct | 1483 ms | 6428 KB | Output is correct |
3 | Correct | 1460 ms | 6364 KB | Output is correct |
4 | Correct | 1414 ms | 6392 KB | Output is correct |
5 | Correct | 1413 ms | 6520 KB | Output is correct |
6 | Correct | 1436 ms | 6520 KB | Output is correct |
7 | Correct | 1454 ms | 6520 KB | Output is correct |
8 | Correct | 1398 ms | 6316 KB | Output is correct |
9 | Correct | 1402 ms | 6416 KB | Output is correct |
10 | Correct | 1415 ms | 6340 KB | Output is correct |
11 | Correct | 1389 ms | 6516 KB | Output is correct |
12 | Correct | 1401 ms | 6392 KB | Output is correct |
13 | Correct | 1448 ms | 6448 KB | Output is correct |
14 | Correct | 1437 ms | 6344 KB | Output is correct |
15 | Correct | 1467 ms | 6500 KB | Output is correct |
16 | Correct | 269 ms | 5060 KB | Output is correct |
17 | Correct | 289 ms | 5100 KB | Output is correct |
18 | Correct | 263 ms | 5048 KB | Output is correct |
19 | Correct | 272 ms | 5140 KB | Output is correct |
20 | Correct | 264 ms | 4956 KB | Output is correct |
21 | Correct | 1786 ms | 6320 KB | Output is correct |
22 | Correct | 1733 ms | 6320 KB | Output is correct |
23 | Correct | 1751 ms | 6328 KB | Output is correct |
24 | Correct | 1835 ms | 6536 KB | Output is correct |
25 | Correct | 1669 ms | 6436 KB | Output is correct |
26 | Correct | 1938 ms | 6300 KB | Output is correct |
27 | Correct | 1938 ms | 6520 KB | Output is correct |
28 | Correct | 1928 ms | 6392 KB | Output is correct |
29 | Correct | 1892 ms | 6404 KB | Output is correct |
30 | Correct | 1423 ms | 6424 KB | Output is correct |
31 | Correct | 1405 ms | 6264 KB | Output is correct |
32 | Correct | 1411 ms | 6520 KB | Output is correct |
33 | Correct | 1778 ms | 6392 KB | Output is correct |
34 | Correct | 1416 ms | 6444 KB | Output is correct |
35 | Correct | 1425 ms | 6480 KB | Output is correct |
36 | Correct | 1458 ms | 6420 KB | Output is correct |
37 | Correct | 1449 ms | 6484 KB | Output is correct |
38 | Correct | 1447 ms | 6520 KB | Output is correct |
39 | Correct | 18 ms | 1400 KB | Output is correct |
40 | Correct | 18 ms | 1400 KB | Output is correct |
41 | Correct | 18 ms | 1400 KB | Output is correct |
42 | Correct | 23 ms | 1400 KB | Output is correct |
43 | Correct | 23 ms | 1400 KB | Output is correct |
44 | Correct | 20 ms | 1400 KB | Output is correct |
45 | Correct | 20 ms | 1272 KB | Output is correct |
46 | Correct | 21 ms | 1400 KB | Output is correct |
47 | Correct | 20 ms | 1340 KB | Output is correct |
48 | Correct | 20 ms | 1272 KB | Output is correct |
49 | Correct | 18 ms | 1372 KB | Output is correct |
50 | Correct | 18 ms | 1400 KB | Output is correct |
51 | Correct | 48 ms | 1360 KB | Output is correct |
52 | Correct | 19 ms | 1400 KB | Output is correct |
53 | Correct | 18 ms | 1400 KB | Output is correct |
54 | Correct | 12 ms | 1272 KB | Output is correct |
55 | Correct | 12 ms | 1272 KB | Output is correct |
56 | Correct | 12 ms | 1272 KB | Output is correct |
57 | Correct | 11 ms | 1272 KB | Output is correct |
58 | Correct | 11 ms | 1272 KB | Output is correct |
59 | Correct | 1882 ms | 6520 KB | Output is correct |
60 | Correct | 1864 ms | 6356 KB | Output is correct |
61 | Correct | 1841 ms | 6420 KB | Output is correct |
62 | Correct | 1877 ms | 6392 KB | Output is correct |
63 | Correct | 1870 ms | 6336 KB | Output is correct |
64 | Execution timed out | 2013 ms | 6444 KB | Time limit exceeded |
65 | Halted | 0 ms | 0 KB | - |