#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
const ll MAXN = 1E3+16;
ll th[MAXN];
vii ans;
vll ve;
void fop (ll i, ll j) {
ans.push_back({ i, j });
ve[i] ^= ve[j];
}
int main () {
cin.tie(nullptr) -> sync_with_stdio(false);
ll n, s;
cin >> n >> s;
if (s == 2) {
ve = vll(n);
for (ll &i : ve) cin >> i;
ll nend = n;
for (ll bit = 19; bit >= 0; bit--) {
vll th = ve;
for (ll &i : th) i = i>>bit&1;
ll j = find(th.begin(), th.begin()+nend, 1) - th.begin();
for (ll i = j+1; i < nend; i++) {
if (th[i]) continue;
fop(i, i-1);
}
for (ll i = j+1; i < nend; i++) {
fop(i-1, i);
}
if (j != nend) nend--;
}
cout << ans.size() << '\n';
for (auto [i, j] : ans) cout << i+1 << ' ' << j+1 << '\n';
return 0;
}
vll ve(n);
for (ll &i : ve) cin >> i;
::ve = ve;
for (ll in = n; in >= 1; in--) {
for (ll i = 0; i < in-1; i++) {
fop(i, i+1);
}
ll j = max_element(ve.begin(), ve.begin()+in) - ve.begin();
for (ll i = j+1; i < in; i++) {
fop(i, i-1);
}
for (ll i = j-2; i >= 0; i--) {
fop(i, i+1);
}
ve.erase(ve.begin()+j);
}
for (ll i = n-2; i >= 0; i--) {
fop(i, i+1);
}
cout << ans.size() << '\n';
for (auto [i, j] : ans) cout << i+1 << ' ' << j+1 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
988 KB |
Output is correct |
5 |
Correct |
3 ms |
1052 KB |
Output is correct |
6 |
Correct |
3 ms |
988 KB |
Output is correct |
7 |
Correct |
4 ms |
988 KB |
Output is correct |
8 |
Correct |
3 ms |
988 KB |
Output is correct |
9 |
Correct |
3 ms |
988 KB |
Output is correct |
10 |
Correct |
5 ms |
988 KB |
Output is correct |
11 |
Correct |
3 ms |
988 KB |
Output is correct |
12 |
Correct |
3 ms |
988 KB |
Output is correct |
13 |
Correct |
3 ms |
1080 KB |
Output is correct |
14 |
Correct |
3 ms |
988 KB |
Output is correct |
15 |
Correct |
3 ms |
988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
988 KB |
Output is correct |
5 |
Correct |
3 ms |
1052 KB |
Output is correct |
6 |
Correct |
3 ms |
988 KB |
Output is correct |
7 |
Correct |
4 ms |
988 KB |
Output is correct |
8 |
Correct |
3 ms |
988 KB |
Output is correct |
9 |
Correct |
3 ms |
988 KB |
Output is correct |
10 |
Correct |
5 ms |
988 KB |
Output is correct |
11 |
Correct |
3 ms |
988 KB |
Output is correct |
12 |
Correct |
3 ms |
988 KB |
Output is correct |
13 |
Correct |
3 ms |
1080 KB |
Output is correct |
14 |
Correct |
3 ms |
988 KB |
Output is correct |
15 |
Correct |
3 ms |
988 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
988 KB |
Output is correct |
18 |
Correct |
5 ms |
1496 KB |
Output is correct |
19 |
Correct |
5 ms |
1496 KB |
Output is correct |
20 |
Correct |
4 ms |
1492 KB |
Output is correct |
21 |
Correct |
4 ms |
1496 KB |
Output is correct |
22 |
Correct |
5 ms |
1496 KB |
Output is correct |
23 |
Correct |
4 ms |
1496 KB |
Output is correct |
24 |
Correct |
5 ms |
1492 KB |
Output is correct |
25 |
Correct |
5 ms |
1496 KB |
Output is correct |
26 |
Correct |
5 ms |
1496 KB |
Output is correct |
27 |
Correct |
5 ms |
1496 KB |
Output is correct |
28 |
Correct |
4 ms |
1496 KB |
Output is correct |
29 |
Correct |
5 ms |
1496 KB |
Output is correct |
30 |
Correct |
5 ms |
1496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
1240 KB |
Output is correct |
6 |
Correct |
3 ms |
1240 KB |
Output is correct |
7 |
Correct |
4 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1240 KB |
Output is correct |
9 |
Correct |
3 ms |
1492 KB |
Output is correct |
10 |
Correct |
3 ms |
1100 KB |
Output is correct |
11 |
Correct |
4 ms |
1236 KB |
Output is correct |
12 |
Correct |
4 ms |
1240 KB |
Output is correct |
13 |
Correct |
4 ms |
1292 KB |
Output is correct |
14 |
Correct |
5 ms |
1236 KB |
Output is correct |
15 |
Correct |
5 ms |
1496 KB |
Output is correct |