Submission #620793

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

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

int n;
int a[30];
int ok[(int)2e6][30];
int dp[30][(int)2e6];
int chk[30];

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 Runtime error 1226 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1226 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1226 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -