이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, k; cin >> n >> k;
vector<int> a(n), b(k), cnt(k);
for (int i = 0; i < n; ++i) {
cin >> a[i];
b[i % k] = (b[i % k] + a[i]) % k;
}
for (int i = 1; i < n % k; ++i) {
if (b[i] != b[i - 1]) {
cout << -1;
exit(0);
}
}
for (int i = n % k + 1; i < k; ++i) {
if (b[i] != b[i - 1]) {
cout << -1;
exit(0);
}
}
vector<array<int, 2>> res;
for (int i = 1; i < n; ++i) {
while (a[i] < a[i - 1]) {
a[i] += k;
res.push_back({1, i});
}
}
for (int i = 1; i < n; ++i) {
int dif = a[i] - a[i - 1];
while (dif--) {
for (int j = i - k; j >= 0; j -= k) {
res.push_back({2, j});
}
for (int j = 0; j < i % k; ++j) {
++cnt[j];
}
}
}
for (int i = 0; i < k - 1; ++i) {
while (cnt[i] > 0) {
res.push_back({1, i});
cnt[i] -= k;
}
}
int rem = -cnt[0];
while (rem--) {
for (int j = n % k; j < n; j += k) {
res.push_back({2, j});
}
}
cout << res.size() << "\n";
for (auto [t, x] : res) {
cout << t << " " << x + 1 << "\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |