Submission #796784

#TimeUsernameProblemLanguageResultExecution timeMemory
796784GusterGoose27Festivals in JOI Kingdom 2 (JOI23_festival2)C++17
10 / 100
647 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; int n, mod; bool chosen[16]; int ans = 0; bool works(vector<pii> &v) { vector<pii> s, t; for (int i = 0; i < n; i++) { s.push_back(pii(v[i].first, i)); t.push_back(pii(v[i].second, i)); } sort(s.begin(), s.end()); sort(t.begin(), t.end()); int a = 0, b = 0; int r = -1; for (int i = 0; i < n; i++) { if (s[i].first < r) continue; a++; r = v[s[i].second].second; } r = -1; for (int i = 0; i < n; i++) { if (v[t[i].second].first < r) continue; b++; r = t[i].first; } return b > a; } void make(vector<pii> &v, int cur = 0) { if (cur == n) { ans += works(v); return; } for (int i = 0; i < 2*n; i++) { if (chosen[i]) continue; chosen[i] = 1; for (int j = i+1; j < 2*n; j++) { if (chosen[j]) continue; chosen[j] = 1; v.push_back(pii(i, j)); make(v, cur+1); v.pop_back(); chosen[j] = 0; } chosen[i] = 0; return; } } int main() { cin >> n >> mod; assert(n <= 8); vector<pii> v; make(v); cout << ans%mod << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...