Submission #936190

#TimeUsernameProblemLanguageResultExecution timeMemory
936190AdamGSJOIRIS (JOI16_joiris)C++17
0 / 100
0 ms348 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(); rep(i, n) cout << T[i] << " "; cout << '\n'; if(n%k==0) { while(T[n-1]<k) { rep(i, k) ++T[n-i-1]; P.pb({2, n-k+1}); } norm(); wypisz(); } int ile=0; rep(i, n-1) if(T[i]!=T[n-1]) ++ile; if(ile%k==0) { rep(i, n-k+1) { while(T[i]%k!=T[n-1]%k) { P.pb({2, i}); rep(j, k) ++T[i+j]; } } } else if((n-ile)%k==0) { for(int i=n-1; i>k; --i) { while(T[i]%k!=T[0]%k) { P.pb({2, i-k+2}); 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...