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>
#define endl '\n'
using namespace std;
int n, k, h[64];
vector<pair<int, int> > moves;
void print_ans(bool t)
{
if(!t)
{
cout<<-1<<endl;
exit(0);
}
cout<<moves.size()<<endl;
for(int i=0; i<moves.size(); i++) cout<<moves[i].first<<" "<<moves[i].second+1<<endl;
exit(0);
}
int rm;
int ost[64];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(int i=0; i<n; i++)
{
cin>>h[i];
ost[i%k]+=h[i];
}
rm=n%k;
if(rm!=0)
{
for(int i=0; i<rm-1; i++) if(ost[i]%k!=ost[i+1]%k) print_ans(0);
for(int i=rm; i<k-1; i++) if(ost[i]%k!=ost[i+1]%k) print_ans(0);
}
else
{
for(int i=0; i<k-1; i++) if(ost[i]%k!=ost[i+1]%k) print_ans(0);
}
for(int i=n-2; i>=0; i--)
{
while(h[i]<h[i+1])
{
moves.push_back({1, i});
h[i]+=k;
}
}
int id=n-1, br=0;
vector<int> vr, vr2;
for(int i=h[n-1]+1; i<=h[0]; i++)
{
while(id && h[id-1]<i) id--;
int l=n-id;
for(int j=id; j<=n-k; j+=k) moves.push_back({2, j});
if(l%k) vr.push_back(l%k);
}
int t=vr.size();
for(int i=1; i<k; i++)
{
for(int s=0; s<vr.size(); s+=k)
{
moves.push_back({1, n-i});
for(int tj=s; tj<s+k; tj++)
{
if(tj>=vr.size()) vr.push_back(n);
vr[tj]--;
}
}
vr2.resize(0);
for(int s=0; s<vr.size(); s++) if(vr[s]) vr2.push_back(vr[s]);
vr=vr2;
}
for(int i=0; i<vr.size(); i++)
{
for(int j=vr[i]-k; j>=0; j-=k)
{
moves.push_back({2, j});
vr[i]-=k;
}
}
vr2.resize(0);
for(int s=0; s<vr.size(); s++) if(vr[s]) vr2.push_back(vr[s]);
vr=vr2;
while(vr.size()%k)
{
vr.push_back(n-k);
moves.push_back({2, n-k});
}
int ts=vr.size()/k;
for(int i=0; i<n-k; i++)
{
for(int j=0; j<ts; j++) moves.push_back({1, i});
}
print_ans(1);
return 0;
}
Compilation message (stderr)
joiris.cpp: In function 'void print_ans(bool)':
joiris.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0; i<moves.size(); i++) cout<<moves[i].first<<" "<<moves[i].second+1<<endl;
| ~^~~~~~~~~~~~~
joiris.cpp: In function 'int main()':
joiris.cpp:67:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int s=0; s<vr.size(); s+=k)
| ~^~~~~~~~~~
joiris.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | if(tj>=vr.size()) vr.push_back(n);
| ~~^~~~~~~~~~~
joiris.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int s=0; s<vr.size(); s++) if(vr[s]) vr2.push_back(vr[s]);
| ~^~~~~~~~~~
joiris.cpp:80:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int i=0; i<vr.size(); i++)
| ~^~~~~~~~~~
joiris.cpp:89:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int s=0; s<vr.size(); s++) if(vr[s]) vr2.push_back(vr[s]);
| ~^~~~~~~~~~
joiris.cpp:55:17: warning: unused variable 'br' [-Wunused-variable]
55 | int id=n-1, br=0;
| ^~
joiris.cpp:64:9: warning: unused variable 't' [-Wunused-variable]
64 | int t=vr.size();
| ^
# | 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... |