Submission #1117764

#TimeUsernameProblemLanguageResultExecution timeMemory
1117764vjudge1캥거루 (CEOI16_kangaroo)C++17
6 / 100
2074 ms1356 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int32_t main () {

    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0); 

    int N, U, V;
    cin >> N >> U >> V;
    -- U;
    -- V;
    map<long long, int> memo[4];
    function<int(long long, int, int )> func = [&](long long tmp, int ind, int dir) -> int {
        if (ind == V) {
            memo[dir][tmp] = (tmp == 0);
            return (tmp == 0);
        }
        int ans = 0;
        if (dir != 0) {
            bool as = false;
            for (int i = ind + 1;i < N;i ++) if ((tmp & (1LL << i)) > 0) {
                as = true;
                break;
            }
            if (!as) {
                if (memo[2].find(tmp) == memo[2].end()) memo[2][tmp] = 0;
            } else {
                for (int i = ind + 1;i < N;i ++) if ((tmp & (1LL << i)) > 0) {
                    ans = (ans + func ((tmp ^ (1LL << i)), i, 0)) % mod;
                    memo[0][tmp] = (memo[0][(tmp ^ (1LL << i))] + memo[0][tmp]) % mod;
                }
            }
        }
        if (dir != 1) {
            bool as = false;
            for (int i = ind - 1;i >= 0;i --) if ((tmp & (1LL << i)) > 0) {
                as = true;
                break;
            }
            if (!as) {
                if (memo[3].find(tmp) == memo[3].end()) memo[3][tmp] = 0;
            } else {
                for (int i = ind - 1;i >= 0;i --) if ((tmp & (1LL << i)) > 0) {
                    ans = (ans + func ((tmp ^ (1LL << i)), i, 1));
                    memo[1][tmp] = (memo[1][(tmp ^ (1LL << i))] + memo[1][tmp]) % mod;
                }
            }
        }
        // memo[tmp] = (memo[tmp] + ans) % mod;
        return ans;
    };
    int answer = func (((1LL << N) - 1) ^ (1LL<< U), U, -1);

    // cout << (((1 << N) - 1) ^ (1 << U)) << "\n";
    cout << answer << "\n";
    // for (auto v : memo) {
    //     cout << v.first << " " << v.second << "\n";
    // }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...