이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |