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 <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 (stderr)
joiris.cpp: In function 'int main()':
joiris.cpp:52:9: warning: unused variable 'mn' [-Wunused-variable]
52 | int mn = *s;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |