Submission #1140490

#TimeUsernameProblemLanguageResultExecution timeMemory
1140490Double_SlashJOIRIS (JOI16_joiris)C++20
100 / 100
4 ms328 KiB
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; int n, k, h[50]; int main() { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> h[i]; vector<pint> ans; auto ver = [&] (int i) { ans.emplace_back(1, i + 1); h[i] += k; }; auto hor = [&] (int i) { ans.emplace_back(2, i + 1); for (int j = i + k; --j >= i;) h[j]++; }; auto inc = [&] (int i) { int mx = *max_element(h + i, h + i + k) + k; for (int j = i; j--;) { while (h[j] <= mx) ver(j); } for (int j = n; --j >= i + k;) { while (h[j] <= mx) ver(j); } hor(i); }; for (int i = 1; i <= n - k; ++i) { while ((h[i] - h[0]) % k) inc(i); } for (int i = n - k; i--;) { while ((h[i + k - 1] - h[n - 1]) % k) inc(i); } int mx = *max_element(h, h + n); for (int i = n; i--;) { while (h[i] < mx) ver(i); if (h[i] != mx) { cout << -1; return 0; } } cout << ans.size() << endl; for (auto [a, b]: ans) cout << a << " " << b << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...