#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
b = a;
for (int &i: b) {
i &= 1;
}
bool yay[2] = {true, true};
for (int i = 0; i < n;) {
int j = i;
while (j < n && b[j] == b[i]) {
j += 1;
}
int len = j - i;
yay[b[i]] &= (len % 2 == 0);
i = j;
}
vector<pair<int, int>> ans;
if (yay[0]) {
int mx = *max_element(a.begin(), a.end());
if (mx & 1) {
for (int i = 0; i < n; ++i) {
while (a[i] + 1 < mx) {
ans.emplace_back(1, i);
a[i] += 2;
}
}
} else {
for (int i = 0; i < n; ++i) {
while (a[i] < mx) {
a[i] += 2;
ans.emplace_back(1, i);
}
}
}
auto [f, s] = minmax_element(a.begin(), a.end());
assert(*f + 1 == *s);
mx = *f;
int mn = *s;
for (int i = 0; i < n;) {
if (b[i] == 1) {
i += 1;
continue;
}
int j = i;
while (j < n && b[i] == b[j]) {
ans.emplace_back(2, j);
j += 2;
}
i = j;
}
for (auto [x, y] : ans) {
cout << x << " " << y + 1 << endl;
}
} else if (yay[1]) {
int mx = *max_element(a.begin(), a.end());
if (mx & 1) {
for (int i = 0; i < n; ++i) {
while (a[i]< mx) {
ans.emplace_back(1, i);
a[i] += 2;
}
}
} else {
for (int i = 0; i < n; ++i) {
while (a[i] + 1 < mx) {
a[i] += 2;
ans.emplace_back(1, i);
}
}
}
auto [f, s] = minmax_element(a.begin(), a.end());
assert(*f + 1 == *s);
mx = *f;
int mn = *s;
for (int i = 0; i < n;) {
b[i] = a[i] - mn;
if (b[i] == 1) {
i += 1;
continue;
}
int j = i;
while (j < n && b[i] == b[j]) {
ans.emplace_back(2, j);
j += 2;
}
i = j;
}
for (auto [x, y] : ans) {
cout << x << " " << y + 1 << endl;
}
} else {
cout << -1;
}
return 0;
}
Compilation message
joiris.cpp: In function 'int main()':
joiris.cpp:52:9: warning: unused variable 'mn' [-Wunused-variable]
52 | int mn = *s;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |