This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld double
const int INF = 1e18;
const int mod = 12345;
const int sz = 1e6 + 5;
bool is_valid(vector < int > cl , int n)
{
int cnt = 0;
if(cl[0] > cl[1]) cnt = 1;
else cnt = 2;
for(int i = 2;i < n;i++)
{
if(cnt & 1){
if(cl[i] < cl[i - 1]) return false;
}
else{
if(cl[i] > cl[i - 1]) return false;
}
cnt++;
}
return true;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n , s , f;
cin >> n >> s >> f;
vector < int > cl;
for(int i = 1;i <= n;i++){
cl.push_back(i);
}
int ans = 0;
while(next_permutation(cl.begin() , cl.end()))
{
if(!(cl[0] == s && cl[n - 1] == f)) continue;
if(is_valid(cl , n))
{
ans++;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |