#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
int n, k, a[N];
vector< pair<int, int> > V;
void PlaceV(int x){
V.pb({1, x});
a[x] += k;
}
void PlaceH(int x){
V.pb({2, x});
for(int i = 0; i < k; i++) a[x + i] ++;
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int j = 0; j < k + 2; j++){
if(j == k + 1) return cout << "-1\n", 0;
for(int i = 2; i + k - 1 <= n; i++){
while((a[i - 1] % k) != (a[i] % k)){
PlaceH(i);
}
}
int fl = 0;
for(int i = 2; i <= n; i++){
if((a[i - 1] % k) != (a[i] % k)) fl = 1;
}
if(!fl) break;
PlaceH(1);
}
int mx = *max_element(a + 1, a + n + 1);
shuffle(all(V), rng);
for(int i = 1; i <= n; i++){
while(a[i] < mx) PlaceV(i);
}
int s = V.size();
while(V.size() + n <= 10000){
for(int j = 1; j <= n; j++) PlaceV(j);
}
cout << V.size() << '\n';
for(auto x : V) cout << x.F << " " << x.S << '\n';
return 0;
}
Compilation message
joiris.cpp: In function 'int main()':
joiris.cpp:53:6: warning: unused variable 's' [-Wunused-variable]
int s = V.size();
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
632 KB |
Output is correct |
8 |
Correct |
6 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Incorrect |
6 ms |
632 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
632 KB |
Output is correct |
8 |
Correct |
6 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Incorrect |
6 ms |
632 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
632 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
8 ms |
632 KB |
Output is correct |
8 |
Correct |
6 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Incorrect |
6 ms |
632 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |