This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |