This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
typedef long long ll;
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;
#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (106)
ll n,k,A[MAXN],o[MAXN];
int main(){
FAST
cin>>n>>k;
FOR(i,1,n)cin>>A[i],o[i]=A[i];
auto mod=[&](vector<pi>&v,ll&p){
ll x=*min_element(A+1,A+n+1);
FOR(i,1,n)A[i]-=x;
p -= x, p += k, p %= k;
while(*max_element(A+1,A+n+1)>=k){
v.eb(1,min_element(A+1,A+n+1)-A), A[min_element(A+1,A+n+1)-A] += k;
ll x=*min_element(A+1,A+n+1);
FOR(i,1,n)A[i]-=x;
p -= x, p += k, p %= k;
}
};
vector<pi> moves;
auto can=[&](ll p){
FOR(i,1,n)A[i]=o[i];
moves.clear();
mod(moves,p);
FOR(i,1,n-k+1) {
while (A[i]%k != p) {
moves.eb(0,i); // 0 means horizontal
FOR(j,i,i+k-1){
++ A[j];
}
mod(moves,p);
}
}
FOR(i,1,n)if(A[i]%k!=p)return 0;
assert(*max_element(A+1,A+n+1)==0);
return 1;
};
FOR(p,0,k-1) if(can(p)) {
cout<<moves.size()<<'\n';
for(auto i:moves) {
cout<<2-i.f<<' '<<i.s<<'\n';
}
return 0;
}
cout<<"-1\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... |