Submission #620791

# Submission time Handle Problem Language Result Execution time Memory
620791 2022-08-03T09:14:44 Z 이동현(#8521) Ruins 3 (JOI20_ruins3) C++17
0 / 100
2151 ms 487020 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = (int)1e9 + 7;

int n;
int a[27];
int ok[1594323 + 4][13];
int dp[28][1594323 + 4];
int chk[27];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

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

        chk[a[i]] = 1;
    }

    int v3 = 1;
    for(int i = 1; i <= n; ++i){
        v3 *= 3;
    }

    for(int i = 0; i < v3; ++i){
        for(int j = 0; j < n; ++j){
            int lc = 0, rc = 0;
            int ii = i;

            for(int x = n - 1; x > j; --x){
                int i3 = ii % 3;

                lc += i3, rc += 2 - i3;

                if(rc) --rc;
                else --lc;

                ii /= 3;
            }

            for(int x = j; x >= 0; --x){
                int i3 = ii % 3;

                if(x == j && i3 == 2){
                    break;
                }

                lc += i3, rc += 1 - i3;
                if(x < j) ++rc;

                if(rc) --rc;
                else{
                    ok[i][j] = 1;

                    break;
                }

                ii /= 3;
            }
        }
    }

    dp[1][0] = 1;

    for(int i = 1; i <= n * 2; ++i){
        for(int j = 0; j < v3; ++j){
            int bt = v3 / 3;

            for(int k = 0; k < n; ++k){
                if(ok[j][k] == chk[i]){
                    (dp[i + 1][j + bt] += dp[i][j]) %= mod;
                }

                bt /= 3;
            }
        }
    }

    cout << dp[n * 2 + 1][v3 - 1] << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 2151 ms 487020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 2151 ms 487020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 2151 ms 487020 KB Output isn't correct
3 Halted 0 ms 0 KB -