#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 200005
int n;
vector<vii> ans;
int main() {
scanf("%d", &n);
if (n == 8 || n == 16 || n == 32 || n == 64) {
int mx = 2;
int p = mx;
int jmp = 1;
while (mx <= n) {
vii res;
int cur = mx, prv = 0;
REP (j, 1, n + 1) {
if (j > cur - (j - prv) + 1) {
prv = cur;
j = cur + 1;
cur += mx;
if (cur > n) {
break;
}
}
res.pb(j, cur - (j - prv) + 1);
}
ans.pb(res);
if (jmp == 1) {
mx *= 2;
p = mx;
jmp = -1;
} else {
if (mx == 2) {
mx = p * 2;
p = mx;
} else {
mx /= 2;
}
}
}
mx = 2;
p = mx;
jmp = 1;
while (mx <= n) {
vii res;
int cur = mx, prv = 0;
REP (j, 1, n + 1) {
if (j > cur - (j - prv) + 1) {
prv = cur;
j = cur + 1;
cur += mx;
if (cur > n) {
break;
}
}
res.pb(j, cur - (j - prv) + 1);
}
ans.pb(res);
if (jmp == 1) {
mx *= 2;
p = mx;
jmp = -1;
} else {
if (mx == 2) {
mx = p * 2;
p = mx;
} else {
mx /= 2;
}
}
}
} else {
REP (i, 0, n - 1) {
vii res;
for (int j = 1; j + 1 <= n; j += 2) {
res.pb(j, j + 1);
}
if (!res.empty()) ans.pb(res);
res.clear();
for (int j = 2; j + 1 <= n; j += 2) {
res.pb(j, j + 1);
}
if (!res.empty()) ans.pb(res);
}
}
printf("%d\n", (int) ans.size());
REP (i, 0, ans.size()) {
for (ii i : ans[i]) {
printf("CMPSWP R%d R%d ", i.FI, i.SE);
}
printf("\n");
}
return 0;
}
Compilation message
malnarisc.cpp: In function 'int main()':
malnarisc.cpp:10:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
114 | REP (i, 0, ans.size()) {
| ~~~~~~~~~~~~~~~~
malnarisc.cpp:114:2: note: in expansion of macro 'REP'
114 | REP (i, 0, ans.size()) {
| ^~~
malnarisc.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
332 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
not sorted |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
332 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
460 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
460 KB |
Partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
460 KB |
Partially correct |