Submission #997555

#TimeUsernameProblemLanguageResultExecution timeMemory
997555AbitoFestivals in JOI Kingdom 2 (JOI23_festival2)C++17
10 / 100
9026 ms600 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define ppb pop_back #define ep insert #define endl '\n' #define elif else if #define pow pwr #define sqrt sqrtt #define int long long #define ll long long #define y1 YONE typedef unsigned long long ull; using namespace std; const int N=20; int n,P; int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n>>P;int ans=0; for (int mask=0;mask<(1<<(2*n));mask++){ if (__builtin_popcount(mask)!=n) continue; vector<int> a,b; for (int j=1;j<=2*n;j++){ if (mask&(1<<(j-1))) a.pb(j); else b.pb(j); } do{ bool ok=true; for (int i=0;i<n;i++) ok&=(a[i]<b[i]); if (!ok) continue; int ans1=0,r=0; for (int i=0;i<n;i++){ if (a[i]>r){ ans1++; r=b[i]; } } int ans2=0;r=0; while (true){ bool f=0; int idx=-1; for (int i=0;i<n;i++){ if (a[i]<r) continue; if (-1==idx || b[i]<b[idx]){ idx=i; f=1; } } if (!f) break; ans2++; r=b[idx]; }ans+=(ans2>ans1); }while(next_permutation(b.begin(),b.end())); }cout<<ans%P<<endl; 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...