# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1150196 | nguyn | JOIRIS (JOI16_joiris) | C++20 | 1 ms | 320 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 2e5 + 5;
int n, k, a[55];
vector<pii> vec;
void vertical(int i) {
a[i] += k;
vec.pb({1, i});
}
void horizontal(int i) {
for (int j = i; j <= i + k - 1; j++) {
a[j]++;
}
vec.pb({2, i});
}
int query(int i) {
int mx = *max_element(a + i, a + i + k) + k;
for (int j = 1; j < i; j++) {
while(a[j] < mx) vertical(j);
}
for (int j = i + k; j <= n; j++) {
while(a[j] < mx) vertical(j);
}
horizontal(i);
}
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
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] - a[1]) % k) query(i);
}
for (int i = n - k + 1; i >= 1; i--) {
while((a[i + k - 1] - a[n]) % k) query(i);
}
int mx = *max_element(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
while(a[i] < mx) {
vertical(i);
}
if (a[i] != mx) {
cout << -1;
return 0;
}
}
cout << vec.size() << '\n';
for (auto it : vec) {
cout << it.F << ' ' << it.S << '\n';
}
}
Compilation message (stderr)
# | 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... |