#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
mt19937 rng(42);
template<class T>
T randomize(T mod)
{
return uniform_int_distribution<T>(0, mod - 1)(rng);
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N;
vector<vpi> ans;
int32_t main()
{
cout << fixed << setprecision(12);
cerr << fixed << setprecision(4);
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N;
vi arr(N);
iota(ALL(arr), 0);
FOR(i, 1, N)
{
swap(arr[i], arr[randomize(i + 1)]);
}
for (int i = 1; i < N; i += i)
{
for (int j = i; j; j >>= 1)
{
ans.PB(vpi());
for (int k = 0; k < N; k += 2 * j)
{
FOR(m, 0, j)
{
if (k + m + j < N)
{
pii p = {k + m, k + m + j};
if (k / (2 * i) % 2)
{
swap(p.fi, p.se);
}
ans.back().PB(p);
}
//j, j + i.
}
}
}
}
cout << SZ(ans) << '\n';
for (vpi v : ans)
{
for (pii p : v)
{
if (arr[p.fi] > arr[p.se])
{
swap(arr[p.fi], arr[p.se]);
}
cout << "CMPSWP R" << p.fi + 1 << " R" << p.se + 1 << ' ';
}
cout << '\n';
}
FOR(i, 0, N)
{
cerr << arr[i] << ' ';
}
cerr << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
not sorted |