/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 202;
int n;
int S;
int initial[N_MAX];
int v[N_MAX];
vector <pair <int, int>> ans;
void fxor (int a, int b)
{
v[a] ^= v[b];
ans.push_back(make_pair(a, b));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> S;
for(int i = 1; i <= n; i++)
cin >> v[i];
if(S == 1)
{
for(int i = 1; i <= n; i++)
initial[i] = v[i];
for(int k = n; k >= 1; k--)
{
for(int i = 1; i < n && i <= k; i++)
fxor(i, i + 1);
int pos = -1;
for(int i = 1; i <= k; i++)
if(pos == -1 || initial[i] > initial[pos])
pos = i;
for(int i = pos - 2; i >= 1; i--)
fxor(i, i + 1);
for(int i = pos + 1; i <= k; i++)
fxor(i, i - 1);
int aux = initial[pos];
for(int i = pos; i < k; i++)
initial[i] = initial[i + 1];
initial[k] = aux;
}
}
else
{
for(int bit = 19, k = n; bit >= 0 && k >= 1; bit--)
{
bool ok = false;
for(int i = 1; i <= k; i++)
if(((v[i] >> bit) & 1) == 1)
ok = true;
if(ok == true)
{
for(int i = 2; i <= k; i++)
if(((v[i] >> bit) & 1) == 0)
fxor(i, i - 1);
for(int i = 1; i <= k - 1; i++)
if(((v[i] >> bit) & 1) == 1)
fxor(i, i + 1);
k--;
}
}
}
cout << ans.size() << "\n";
for(pair <int, int> &p : ans)
cout << p.first << " " << p.second << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
752 KB |
Output is correct |
5 |
Correct |
5 ms |
752 KB |
Output is correct |
6 |
Correct |
5 ms |
752 KB |
Output is correct |
7 |
Correct |
5 ms |
752 KB |
Output is correct |
8 |
Correct |
5 ms |
752 KB |
Output is correct |
9 |
Correct |
5 ms |
752 KB |
Output is correct |
10 |
Correct |
5 ms |
752 KB |
Output is correct |
11 |
Correct |
5 ms |
752 KB |
Output is correct |
12 |
Correct |
5 ms |
752 KB |
Output is correct |
13 |
Correct |
5 ms |
752 KB |
Output is correct |
14 |
Correct |
5 ms |
752 KB |
Output is correct |
15 |
Correct |
5 ms |
752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
5 ms |
752 KB |
Output is correct |
5 |
Correct |
5 ms |
752 KB |
Output is correct |
6 |
Correct |
5 ms |
752 KB |
Output is correct |
7 |
Correct |
5 ms |
752 KB |
Output is correct |
8 |
Correct |
5 ms |
752 KB |
Output is correct |
9 |
Correct |
5 ms |
752 KB |
Output is correct |
10 |
Correct |
5 ms |
752 KB |
Output is correct |
11 |
Correct |
5 ms |
752 KB |
Output is correct |
12 |
Correct |
5 ms |
752 KB |
Output is correct |
13 |
Correct |
5 ms |
752 KB |
Output is correct |
14 |
Correct |
5 ms |
752 KB |
Output is correct |
15 |
Correct |
5 ms |
752 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
5 ms |
752 KB |
Output is correct |
18 |
Correct |
9 ms |
1008 KB |
Output is correct |
19 |
Correct |
8 ms |
1008 KB |
Output is correct |
20 |
Correct |
8 ms |
1008 KB |
Output is correct |
21 |
Correct |
8 ms |
1008 KB |
Output is correct |
22 |
Correct |
8 ms |
1008 KB |
Output is correct |
23 |
Correct |
8 ms |
1008 KB |
Output is correct |
24 |
Correct |
9 ms |
1132 KB |
Output is correct |
25 |
Correct |
8 ms |
1008 KB |
Output is correct |
26 |
Correct |
8 ms |
1008 KB |
Output is correct |
27 |
Correct |
8 ms |
1008 KB |
Output is correct |
28 |
Correct |
10 ms |
1008 KB |
Output is correct |
29 |
Correct |
8 ms |
1008 KB |
Output is correct |
30 |
Correct |
8 ms |
1008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |