Submission #351860

#TimeUsernameProblemLanguageResultExecution timeMemory
351860YJUJOIRIS (JOI16_joiris)C++14
0 / 100
4 ms748 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=2e5+5; const ld pi=acos(-1); const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,k,a[N],st,ma=0; vector<pll> ans; void out(){ //REP(i,n)cout<<a[i]<<(i==n-1?"\n":" "); } int main(){ //ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>k; REP(i,n)cin>>a[i]; for(st=0;st+k<=n;st+=k){ for(int i=n-1;i>=st;i--){ while(a[i]<a[i+1])ans.pb(mp(0,i)),a[i]+=k; } out(); for(int i=n-k;i-1>=st;i--){ while(a[i-1]>a[i]){ for(int j=i+k;j<n;j++){ while(a[j]<a[i]+1)ans.pb(mp(0,j)),a[j]+=k; } for(int j=0;j<st;j+=k){ while(a[j]<a[i]+1){ ans.pb(mp(1,j)); for(int id=j;id<j+k;id++)a[id]+=1; } } ans.pb(mp(1,i)); for(int j=0;j<n;j++){ if(j>=i&&j<i+k)continue; a[j]--; } } } out(); } for(int i=1;i<st;i++)if(a[i]!=a[i-1]){ cout<<"-1\n";return 0; } for(int i=st;i<n;i++){while(a[i]<a[0])ans.pb(mp(0,i)),a[i]+=k;ma=max(ma,a[i]);} for(int i=st;i<n;i++)while(a[i]<ma)ans.pb(mp(0,i)),a[i]+=k; while(a[0]<ma){ for(int i=0;i+k<=n;i+=k){ ans.pb(mp(1,i)); for(int j=i;j<i+k;j++)a[j]++; } } out(); for(int i=st;i<n;i++)if(a[i]!=ma){ cout<<"-1\n";return 0; } cout<<SZ(ans)<<"\n"; for(auto i:ans)cout<<i.X+1<<" "<<i.Y+1<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...