제출 #936188

#제출 시각아이디문제언어결과실행 시간메모리
936188AdamGSJOIRIS (JOI16_joiris)C++17
30 / 100
1 ms756 KiB
#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=57; int T[LIM], n, k; vector<pair<int,int>>P; void wypisz() { rep(i, n) if(T[i]!=0) { cout << -1 << '\n'; exit(0); } cout << P.size() << '\n'; for(auto i : P) cout << i.st << " " << i.nd << '\n'; exit(0); } void norm() { int ma=0; rep(i, n) ma=max(ma, T[i]); rep(i, n) { while(T[i]<=ma-k) { T[i]+=k; P.pb({1, i+1}); } } int mi=T[0]; rep(i, n) mi=min(mi, T[i]); rep(i, n) T[i]-=mi; } void poziom(int x) { int ma=0; rep(i, k) ma=max(ma, T[x+i]+1); P.pb({2, x+1}); rep(i, n) if(i<x || x+k<=i) { if(T[i]<ma) { T[i]+=k; P.pb({1, i+1}); } --T[i]; } } int main() { //ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; rep(i, n) cin >> T[i]; norm(); if(n==k) { while(T[0]<k) { P.pb({2, 1}); rep(i, n) ++T[i]; } norm(); wypisz(); } rep(i, n-k-1) { int x=(T[i]-T[i+1]+k)%k; rep(j, x) poziom(i+1); norm(); } int x=T[0]; rep(i, x) poziom(n-k); norm(); while(T[n-1]<k) { rep(i, k) ++T[n-i-1]; P.pb({2, n-k+1}); } norm(); if(n%k==0) wypisz(); rep(i, n-k+1) { while(T[i]%k!=T[n-1]%k) { P.pb({2, i}); rep(j, k) ++T[i+j]; } } norm(); wypisz(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...