Submission #727840

# Submission time Handle Problem Language Result Execution time Memory
727840 2023-04-21T12:17:00 Z Kahou Ruins 3 (JOI20_ruins3) C++14
100 / 100
445 ms 1876 KB
/* In the name of God, aka Allah */
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int mod = 1e9 + 7;
int add(int a, int b) {
        a += b;
        if (a >= mod) a -= mod;
        if (a < 0) a += mod;
        return a;
}
int mul(int a, int b) {
        return 1ll*a*b%mod;
}
int pw(int a, int b) {
        int out = 1;
        while (b) {
                if (b&1) out = mul(a, out);
                a = mul(a, a);
                b >>= 1;
        }
        return out;
}

const int N = 605;
int n, a[N<<1], dp[N], f[N], C[N][N];

void solve() {
        C[0][0] = 1;
        for (int x = 1; x < N; x++) {
                C[x][0] = 1;
                for (int y = 1; y < N; y++) {
                        C[x][y] = add(C[x-1][y-1], C[x-1][y]);
                }
        }
        cin >> n;
        for (int i = 1; i <= n; i++) {
                int x;
                cin >> x;
                a[x] = 1;
        }
        f[0] = 1;
        for (int x = 1; x <= n; x++) {
                for (int i = 1; i <= x; i++) {
                        f[x] = add(f[x], mul(C[x-1][i-1], mul(mul(f[i-1], f[x-i]), x-i+2)));
                }
        }
        dp[0] = 1;
        int c0 = 0, c1 = 0;
        for (int i = 2*n; i >= 1; i--) {
                if (!a[i]) {
                        for (int x = 0; x <= n; x++) {
                                if (x <= c0) dp[x] = 0;
                                else dp[x] = mul(dp[x], x-c0);
                        }
                        c0++;
                }
                else {
                        for (int x = c1+1; x >= 1; x--) {
                                for (int y = 0; y < x; y++) {
                                        dp[x] = add(dp[x], mul(dp[y], mul(mul(C[c1-y][x-y-1], f[x-y-1]), x-y+1)));
                                }
                        }
                        c1++;
                }
        }
        cout << mul(dp[n], pw(2, mod-1-n)) << endl;
}
int main() {
        ios::sync_with_stdio(0), cin.tie(0);
        solve();
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 2 ms 1764 KB Output is correct
5 Correct 2 ms 1748 KB Output is correct
6 Correct 2 ms 1764 KB Output is correct
7 Correct 2 ms 1756 KB Output is correct
8 Correct 2 ms 1764 KB Output is correct
9 Correct 2 ms 1756 KB Output is correct
10 Correct 2 ms 1760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 2 ms 1764 KB Output is correct
5 Correct 2 ms 1748 KB Output is correct
6 Correct 2 ms 1764 KB Output is correct
7 Correct 2 ms 1756 KB Output is correct
8 Correct 2 ms 1764 KB Output is correct
9 Correct 2 ms 1756 KB Output is correct
10 Correct 2 ms 1760 KB Output is correct
11 Correct 2 ms 1748 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 4 ms 1748 KB Output is correct
15 Correct 3 ms 1760 KB Output is correct
16 Correct 2 ms 1748 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 2 ms 1748 KB Output is correct
19 Correct 3 ms 1748 KB Output is correct
20 Correct 2 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 2 ms 1748 KB Output is correct
4 Correct 2 ms 1764 KB Output is correct
5 Correct 2 ms 1748 KB Output is correct
6 Correct 2 ms 1764 KB Output is correct
7 Correct 2 ms 1756 KB Output is correct
8 Correct 2 ms 1764 KB Output is correct
9 Correct 2 ms 1756 KB Output is correct
10 Correct 2 ms 1760 KB Output is correct
11 Correct 2 ms 1748 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 2 ms 1748 KB Output is correct
14 Correct 4 ms 1748 KB Output is correct
15 Correct 3 ms 1760 KB Output is correct
16 Correct 2 ms 1748 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 2 ms 1748 KB Output is correct
19 Correct 3 ms 1748 KB Output is correct
20 Correct 2 ms 1748 KB Output is correct
21 Correct 260 ms 1752 KB Output is correct
22 Correct 279 ms 1756 KB Output is correct
23 Correct 314 ms 1756 KB Output is correct
24 Correct 267 ms 1748 KB Output is correct
25 Correct 265 ms 1752 KB Output is correct
26 Correct 277 ms 1756 KB Output is correct
27 Correct 274 ms 1876 KB Output is correct
28 Correct 284 ms 1756 KB Output is correct
29 Correct 264 ms 1756 KB Output is correct
30 Correct 445 ms 1748 KB Output is correct
31 Correct 360 ms 1756 KB Output is correct
32 Correct 400 ms 1752 KB Output is correct
33 Correct 431 ms 1868 KB Output is correct
34 Correct 355 ms 1796 KB Output is correct
35 Correct 391 ms 1748 KB Output is correct
36 Correct 425 ms 1748 KB Output is correct