# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1116924 | 2024-11-22T15:11:50 Z | byebye75 | 유적 3 (JOI20_ruins3) | C++14 | 314 ms | 8948 KB |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int n; int a[1205]; int dp[1205][1205], C[1205][1205]; int fact[1205]; void build_pascal(){ fact[0] = 1; for(int i = 1; i <= 1200 ; ++i) fact[i] = (1LL * fact[i - 1] * i) % MOD; C[0][0] = 1; for(int i = 1; i <= 1200 ; ++i){ C[i][0] = 1; for(int j = 1; j <= i ; ++j){ C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; if(C[i][j] >= MOD) C[i][j] -= MOD; } } } inline int lgput(int x, int p){ int ans = 1, aux = x; for(int i = 1; i <= p ; i = i << 1){ if(i & p) ans = (1LL * ans * aux) % MOD; aux = (1LL * aux * aux) % MOD; } return ans; } int main() { // freopen("1.in", "r", stdin); scanf("%d", &n); for(int i = 1; i <= n ; ++i) scanf("%d", &a[i]); if(a[1] == 1 || a[n] != 2 * n){ printf("0"); return 0; } build_pascal(); dp[0][n + 1] = 1; for(int l = 1, i = 0; i < n ; ++i, l = 1 - l){ for(int j = n + 1; j >= 1 ; --j){ if(dp[i][j] == 0) continue ; int libere = a[i + 1] - (i + 1) - (n - j + 1); for(int k = 0; k <= min(n, min(libere, j)) ; ++k){ if(j - k > n - i) continue ; int pos = 1; if(k == 0) pos = (n - (j - k) + 1) * 2 - (a[i + 1] - (libere - k) - 1); int add = 1LL * dp[i][j] * C[2 * k][k] % MOD * C[libere][k] % MOD * fact[k] % MOD; add = 1LL * add * pos % MOD; dp[i + 1][j - k] = (dp[i + 1][j - k] + add); if(dp[i + 1][j - k] >= MOD) dp[i + 1][j - k] -= MOD; } } } int Sol = dp[n][1]; for(int i = 1; i <= n ; ++i) Sol = (1LL * Sol * lgput(2, MOD - 2)) % MOD; printf("%d", Sol); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 6736 KB | Output is correct |
2 | Correct | 4 ms | 6764 KB | Output is correct |
3 | Correct | 4 ms | 6736 KB | Output is correct |
4 | Correct | 1 ms | 436 KB | Output is correct |
5 | Correct | 4 ms | 6736 KB | Output is correct |
6 | Correct | 4 ms | 6904 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 4 ms | 6736 KB | Output is correct |
9 | Correct | 4 ms | 6736 KB | Output is correct |
10 | Correct | 4 ms | 6736 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 6736 KB | Output is correct |
2 | Correct | 4 ms | 6764 KB | Output is correct |
3 | Correct | 4 ms | 6736 KB | Output is correct |
4 | Correct | 1 ms | 436 KB | Output is correct |
5 | Correct | 4 ms | 6736 KB | Output is correct |
6 | Correct | 4 ms | 6904 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 4 ms | 6736 KB | Output is correct |
9 | Correct | 4 ms | 6736 KB | Output is correct |
10 | Correct | 4 ms | 6736 KB | Output is correct |
11 | Correct | 5 ms | 6904 KB | Output is correct |
12 | Correct | 4 ms | 6736 KB | Output is correct |
13 | Correct | 4 ms | 6596 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 4 ms | 6736 KB | Output is correct |
17 | Correct | 1 ms | 336 KB | Output is correct |
18 | Correct | 4 ms | 6736 KB | Output is correct |
19 | Correct | 4 ms | 6736 KB | Output is correct |
20 | Correct | 5 ms | 6736 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 6736 KB | Output is correct |
2 | Correct | 4 ms | 6764 KB | Output is correct |
3 | Correct | 4 ms | 6736 KB | Output is correct |
4 | Correct | 1 ms | 436 KB | Output is correct |
5 | Correct | 4 ms | 6736 KB | Output is correct |
6 | Correct | 4 ms | 6904 KB | Output is correct |
7 | Correct | 1 ms | 336 KB | Output is correct |
8 | Correct | 4 ms | 6736 KB | Output is correct |
9 | Correct | 4 ms | 6736 KB | Output is correct |
10 | Correct | 4 ms | 6736 KB | Output is correct |
11 | Correct | 5 ms | 6904 KB | Output is correct |
12 | Correct | 4 ms | 6736 KB | Output is correct |
13 | Correct | 4 ms | 6596 KB | Output is correct |
14 | Correct | 1 ms | 336 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 4 ms | 6736 KB | Output is correct |
17 | Correct | 1 ms | 336 KB | Output is correct |
18 | Correct | 4 ms | 6736 KB | Output is correct |
19 | Correct | 4 ms | 6736 KB | Output is correct |
20 | Correct | 5 ms | 6736 KB | Output is correct |
21 | Correct | 9 ms | 8948 KB | Output is correct |
22 | Correct | 6 ms | 8528 KB | Output is correct |
23 | Correct | 8 ms | 8628 KB | Output is correct |
24 | Correct | 9 ms | 8528 KB | Output is correct |
25 | Correct | 1 ms | 336 KB | Output is correct |
26 | Correct | 4 ms | 6736 KB | Output is correct |
27 | Correct | 1 ms | 504 KB | Output is correct |
28 | Correct | 6 ms | 8528 KB | Output is correct |
29 | Correct | 2 ms | 336 KB | Output is correct |
30 | Correct | 314 ms | 8796 KB | Output is correct |
31 | Correct | 160 ms | 8776 KB | Output is correct |
32 | Correct | 228 ms | 8776 KB | Output is correct |
33 | Correct | 294 ms | 8792 KB | Output is correct |
34 | Correct | 162 ms | 8788 KB | Output is correct |
35 | Correct | 231 ms | 8776 KB | Output is correct |
36 | Correct | 307 ms | 8804 KB | Output is correct |