답안 #728029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728029 2023-04-21T20:25:22 Z ilia_rr 유적 3 (JOI20_ruins3) C++17
100 / 100
465 ms 348 KB
// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
// Written by Ilia Rahbar

// #pragma GCC optimize ("O3,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target ("abm,bmi,bmi2,tbm,avx2")

#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define sz(x) int(x.size())
#define ai(x) array <int, x>
#define be(x) x.begin(), x.end()
#define pb push_back
#define el '\n'
#define sp ' '
#define fi first 
#define se second

const int M = 1e9 + 7, N = 605;

int n, a[N * 2], x, z, f[N] = {1}, dp[N] = {1}, fact[N] = {1, 1}, invfact[N] = {1, 1};

int pwr(int a, int b)
{
    if (!b)
        return 1;
    
    int x = pwr(a, b / 2);

    return x * x % M * (b & 1 ? a : 1) % M;
}

int c(int a, int b)
{
    return fact[a] * invfact[b] % M * invfact[a - b] % M;
}

int32_t main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    for (int i = 2; i < N; i++)
        fact[i] = fact[i-1] * i % M, invfact[i] = pwr(fact[i], M - 2);

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> x, a[x] = 1;

    for (int i = 1; i < N; i++)
        for (int j = 0; j < i; j++)
            f[i] = (f[i] + f[j] * f[i - j - 1] % M * c(i - 1, j) % M * (i - j + 1) % M) % M;

    for (int i = 1; i <= n * 2; i++)
    {
        if (a[n * 2 - i + 1])
        {
            for (int x = i - z; x; x--)
            {
                for (int y = 0; y < x; y++)
                {
                    dp[x] = (dp[x] + dp[y] * f[x - y - 1] % M * c(i - z - 1 - y, x - y - 1) % M * (x - y + 1) % M) % M;
                }
            }
        }

        else
        {
            for (int x = 0; x <= n; x++) 
                dp[x] = max(int(0), dp[x] * (x - z)) % M;

            z++;
        }
    }
    

    cout << dp[n] * pwr(2, (M - 2) * n) % M;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 3 ms 336 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 340 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 4 ms 344 KB Output is correct
18 Correct 3 ms 336 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 4 ms 340 KB Output is correct
21 Correct 411 ms 340 KB Output is correct
22 Correct 465 ms 340 KB Output is correct
23 Correct 412 ms 340 KB Output is correct
24 Correct 411 ms 340 KB Output is correct
25 Correct 437 ms 340 KB Output is correct
26 Correct 413 ms 340 KB Output is correct
27 Correct 424 ms 340 KB Output is correct
28 Correct 403 ms 340 KB Output is correct
29 Correct 411 ms 340 KB Output is correct
30 Correct 437 ms 340 KB Output is correct
31 Correct 413 ms 340 KB Output is correct
32 Correct 406 ms 348 KB Output is correct
33 Correct 424 ms 340 KB Output is correct
34 Correct 403 ms 340 KB Output is correct
35 Correct 416 ms 340 KB Output is correct
36 Correct 433 ms 340 KB Output is correct