#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define sec second
#define OPT cin.tie(0); cout.tie(0);
#define pb push_back
#define print(v) cerr << "Ans : "; cout << v << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int oo = INT_MAX;
const ll ooo = LONG_MAX;
bool st(int arr[], int l)
{
for(int i = 2; i<=l-1; i++)
if(!(arr[i-1] <= arr[i] && arr[i] <= arr[i+1]))return false;
return true;
}
int main()
{
int n;
cin >> n;
int arr[n+1];
for(int i = 1; i<=n; i++)
{
arr[i] = n - i + 1;
}
if(n%2 == 0)
{
int c = 1, cnt = 1;
vector<string> ans;
while(st(arr, n) == false)
{
ans.resize(cnt);
if(c)
{
for(int i = 1; i<=n; i+=2)
{
ans[cnt-1] = ans[cnt-1] + "CMPSWP R" + to_string(i) + " R" + to_string(i+1) + " ";
if(arr[i+1] < arr[i])
{
swap(arr[i+1], arr[i]);
}
}
cnt++;
c = 0;
}
else
{
for(int i = 2; i+1<=n; i+=2)
{
ans[cnt-1] = ans[cnt-1] + "CMPSWP R" + to_string(i) + " R" + to_string(i+1) + " ";
if(arr[i+1] < arr[i])
{
swap(arr[i+1], arr[i]);
}
}
ans[cnt-1] = ans[cnt-1] + "CMPSWP R" + to_string(1) + " R" + to_string(n) + " ";
if(arr[1] > arr[n])
{
swap(arr[1], arr[n]);
}
cnt++;
c = 1;
}
}
if(n == 1)cnt = 2;
cout << cnt-1 << endl;
for(auto i : ans)cout << i << endl;
}
else
{
int c = 1, cnt = 1;
vector<string> ans;
while(st(arr, n) == false)
{
ans.resize(cnt);
if(c)
{
for(int i = 1; i+1<=n; i+=2)
{
ans[cnt-1] = ans[cnt-1] + "CMPSWP R" + to_string(i) + " R" + to_string(i+1) + " ";
if(arr[i+1] < arr[i])
{
swap(arr[i+1], arr[i]);
}
}
cnt++;
c = 0;
}
else
{
for(int i = 2; i+1<=n; i+=2)
{
ans[cnt-1] = ans[cnt-1] + "CMPSWP R" + to_string(i) + " R" + to_string(i+1) + " ";
if(arr[i+1] < arr[i])
{
swap(arr[i+1], arr[i]);
}
}
cnt++;
c = 1;
}
}
if(n == 1)cnt = 2;
cout << cnt-1 << endl;
for(auto i : ans)cout << i << endl;
}
//for(int i = 1; i<=n; i++)cout << arr[i] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
212 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
340 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
340 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
340 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
468 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
468 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
468 KB |
Partially correct |