#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pi3 = pair<pii, int>;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define pb push_back
#define minr(a, b) a = min(a, b);
#define maxr(a, b) a = max(a, b);
#define shit cout << "shit\n" << flush;
#define tl while(1&1) continue;
#define rand(l, r) uniform_int_distribution<int64_t>(l,r)(rng)
random_device device; default_random_engine rng(device());
const int Mod = 1e9 + 7; //998244353;
const int LG = 64;
const int SQ = 500;
const int Inf = 2e9 + 10;
const int maxN = 60;
int n, k;
int a[maxN];
vector <pii> ope;
void hor(int idx) {
ope.pb({2, idx});
for(int i = idx; i < idx+k; i++)
a[i]++;
}
void vert(int idx) {
ope.pb({1, idx});
a[idx]+=k;
}
void add(int idx) {
int mx = 0;
for(int i = idx; i < idx+k; i++)
maxr(mx, a[idx]+1);
for(int i = 1; i <= n; i++)
if(i < idx or i >= idx+k)
while(a[i] <= mx)
vert(i);
hor(idx);
}
int main() {
IOS;
cin >> n >> k;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n-k+1; i++)
while(a[i]%k != a[1]%k)
add(i);
for(int i = n; i >= k; i--)
while(a[i]%k != a[n]%k)
add(i-k+1);
int mx = 0;
for(int i = 1; i <= n; i++)
maxr(mx, a[i]);
for(int i = 1; i <= n; i++) {
while(a[i] < mx)
vert(i);
if(a[i] != mx) {
cout << -1;
return 0;
}
}
cout << sz(ope) << "\n";
for(auto [type, idx] : ope)
cout << type << " " << idx << "\n";
}
# | 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... |