Submission #768784

#TimeUsernameProblemLanguageResultExecution timeMemory
768784danikoynovFestivals in JOI Kingdom 2 (JOI23_festival2)C++14
5 / 100
9017 ms300 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 20; int n, mod, used[maxn], p[maxn], visit[maxn]; int l[maxn], r[maxn], ans; void check() { int d = 1; for (int i = 1; i <= 2 * n; i += 2) { l[d] = p[i]; r[d] = p[i + 1]; d ++; } for (int i = 1; i <= n; i ++) { if (l[i] > r[i]) return; if (i != 1 && l[i] < l[i - 1]) return; visit[i] = 0; } int to = 0, cur = 0; for (int i = 1; i <= n; i ++) { if (to < l[i]) { cur ++; visit[i] = 1; to = r[i]; } } /**cout << "---------" << endl; for (int i = 1; i <= n; i ++) cout << l[i] << " " << r[i] << endl;*/ int best = 0; to = 0; while(true) { int mx = -1; for (int i = 1; i <= n; i ++) { if (l[i] > to) { if (mx == -1 || r[i] < r[mx]) mx = i; } } if (mx == -1) break; to = r[mx]; best ++; } if (best > cur) ans ++; } void perm(int pos) { if (pos == 2 * n + 1) check(); else { for (int i = 1; i <= 2 * n; i ++) { if (pos % 2 == 0 && i < p[pos - 1]) continue; if (pos % 2 == 1 && i != 1 && i < p[pos - 2]) continue; if (used[i] == 0) { used[i] = 1; p[pos] = i; perm(pos + 1); p[pos] = 0; used[i] = 0; } } } } void solve() { cin >> n >> mod; perm(1); cout << ans << endl; } int main() { solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...