#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] + "CMP 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] + "CMP 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] + "CMP 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] + "CMP 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] + "CMP 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 |
Incorrect |
1 ms |
212 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
304 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
300 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
Token "CMP" doesn't correspond to pattern "CMPSWP" |
2 |
Halted |
0 ms |
0 KB |
- |