#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 1005;
vector<int> a(maxn);
vector<pair<int, int> > v;
void go(int x, int y) { a[x] ^= a[y]; v.push_back({ x, y }); }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, s; cin >> n >> s;
for (int i = 0; i < n; i++) cin >> a[i];
if (s == 1)
{
vector<int> b = a; b.resize(n);
for (int i = n - 1; i > 0; i--)
{
for (int j = 0; j <= i && j < n - 1; j++) go(j, j + 1);
int mi = max_element(b.begin(), b.end()) - b.begin();
for (int j = mi; j < i; j++) go(j + 1, j);
for (int j = mi - 1; j > 0; j--) go(j - 1, j);
b.erase(b.begin() + mi);
}
go(0, 1);
}
else
{
int m = n;
for (int b = 19; b >= 0; b--)
{
int l = -1;
for (int i = 0; i < m; i++) if (a[i] & (1 << b))
{
l = i;
break;
}
if (l == -1) continue;
for (int i = l; i < m - 1; i++)
if (!(a[i + 1] & (1 << b))) go(i + 1, i);
for (int i = l; i < m - 1; i++) go(i, i + 1);
m--;
}
}
cout << v.size() << "\n";
for (pair<int, int> i : v) cout << i.first+1 << " " << i.second+1 << "\n";
//for (int i = 0; i < n; i++) cout << a[i] << " ";
//cout << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
772 KB |
Output is correct |
5 |
Correct |
6 ms |
728 KB |
Output is correct |
6 |
Correct |
4 ms |
728 KB |
Output is correct |
7 |
Correct |
5 ms |
728 KB |
Output is correct |
8 |
Correct |
4 ms |
728 KB |
Output is correct |
9 |
Correct |
4 ms |
728 KB |
Output is correct |
10 |
Correct |
4 ms |
732 KB |
Output is correct |
11 |
Correct |
4 ms |
728 KB |
Output is correct |
12 |
Correct |
5 ms |
728 KB |
Output is correct |
13 |
Correct |
4 ms |
728 KB |
Output is correct |
14 |
Correct |
6 ms |
728 KB |
Output is correct |
15 |
Correct |
4 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
772 KB |
Output is correct |
5 |
Correct |
6 ms |
728 KB |
Output is correct |
6 |
Correct |
4 ms |
728 KB |
Output is correct |
7 |
Correct |
5 ms |
728 KB |
Output is correct |
8 |
Correct |
4 ms |
728 KB |
Output is correct |
9 |
Correct |
4 ms |
728 KB |
Output is correct |
10 |
Correct |
4 ms |
732 KB |
Output is correct |
11 |
Correct |
4 ms |
728 KB |
Output is correct |
12 |
Correct |
5 ms |
728 KB |
Output is correct |
13 |
Correct |
4 ms |
728 KB |
Output is correct |
14 |
Correct |
6 ms |
728 KB |
Output is correct |
15 |
Correct |
4 ms |
728 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
4 ms |
724 KB |
Output is correct |
18 |
Correct |
6 ms |
980 KB |
Output is correct |
19 |
Correct |
6 ms |
984 KB |
Output is correct |
20 |
Correct |
6 ms |
984 KB |
Output is correct |
21 |
Correct |
7 ms |
984 KB |
Output is correct |
22 |
Correct |
7 ms |
1024 KB |
Output is correct |
23 |
Correct |
6 ms |
984 KB |
Output is correct |
24 |
Correct |
6 ms |
984 KB |
Output is correct |
25 |
Correct |
7 ms |
984 KB |
Output is correct |
26 |
Correct |
7 ms |
984 KB |
Output is correct |
27 |
Correct |
7 ms |
984 KB |
Output is correct |
28 |
Correct |
9 ms |
968 KB |
Output is correct |
29 |
Correct |
7 ms |
988 KB |
Output is correct |
30 |
Correct |
7 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
5 ms |
840 KB |
Output is correct |
6 |
Correct |
5 ms |
916 KB |
Output is correct |
7 |
Correct |
7 ms |
856 KB |
Output is correct |
8 |
Correct |
8 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
6 ms |
856 KB |
Output is correct |
11 |
Correct |
6 ms |
856 KB |
Output is correct |
12 |
Correct |
5 ms |
968 KB |
Output is correct |
13 |
Correct |
5 ms |
856 KB |
Output is correct |
14 |
Correct |
6 ms |
968 KB |
Output is correct |
15 |
Correct |
7 ms |
980 KB |
Output is correct |