Submission #1216786

#TimeUsernameProblemLanguageResultExecution timeMemory
1216786magyarakoosKangaroo (CEOI16_kangaroo)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;

int n, cs, cf;

vector<bool> vis(8);
int i;
bool dir;
int vcnt;
int result;

void backtrack() {
    vis[i] = 1;
    vcnt++;
    dir = !dir;
    if (vcnt == n) {
        result += i == cf;
    } else if (dir) {
        for (int j = i + 1; j < n; j++) {
            if (!vis[j]) {
                swap(i, j);
                backtrack();
                swap(i, j);
            }
        }
    } else {
        for (int j = i - 1; j >= 0; j--) {
            if (!vis[j]) {
                swap(i, j);
                backtrack();
                swap(i, j);
            }
        }
    }
    dir = !dir;
    vcnt--;
    vis[i] = 0;
}

int32_t main() {
    ifstream fin("kangoroo.in");
    ofstream fout("kangoroo.out");
    fin >> n >> cs >> cf;
    cs--, cf--;
    i = cs;
    backtrack();
    dir = 1;
    backtrack();
    fout << result << "\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...