Submission #351909

#TimeUsernameProblemLanguageResultExecution timeMemory
351909YJUJOIRIS (JOI16_joiris)C++14
0 / 100
1 ms364 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],b[N],l[N]; 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]; b[i%k]+=a[i]; } REP(i,n%k){ if(b[i]%k!=b[0]%k){ cout<<"-1\n";return 0; } } for(int i=n%k;i<k;i++){ if(b[i]%k!=b[k-1]%k){ cout<<"-1\n";return 0; } } for(int i=1;i<n;i++)while(a[i]<a[i-1])a[i]+=k,ans.pb(mp(1,i+1)); for(int i=0;i<n;i++){ for(int j=a[i];j<a[i+1];j++){ for(int jj=i-k-1;jj>=0;jj--){ ans.pb(mp(2,jj+1)); } if(i%k!=k-1)--l[i%k]; } } for(int i=k-1;i>=0;i--)l[i]+=l[i+1]; REP(i,n){ while(l[i]<0){ ans.pb(mp(1,i+1)); l[i]+=k; } } if(n%k>=1&&l[0]<l[k-1]){ for(int i=0;i<n%k;i++)l[i]+=k,ans.pb(mp(1,i+1)); } if(n%k>=1){ for(int i=n-k;i>=0;i-=k){ for(int j=0;j<l[0]-l[k-1];j++)ans.pb(mp(2,i+1)); } } cout<<SZ(ans)<<"\n"; for(auto i:ans)cout<<i.X<<" "<<i.Y<<"\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...