# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362505 | denkendoemeer | JOIRIS (JOI16_joiris) | C++14 | 1 ms | 384 KiB |
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>
using namespace std;
int d[105],r[105],v[105];
vector<pair<int,int>>ans;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,k,i,j,e;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++){
scanf("%d",&v[i]);
d[i%k]+=v[i];
}
for(i=0;i<n%k;i++){
if (d[i]%k!=d[0]%k){
printf("-1\n");
return 0;
}
}
for(i=n%k;i<k;i++){
if (d[i]%k!=d[k-1]%k){
printf("-1\n");
return 0;
}
}
for(i=1;i<n;i++){
while(1){
if (v[i-1]>v[i]){
ans.push_back(make_pair(1,i));
v[i]+=k;
}
else
break;
}
}
for(i=0;i<n-1;i++)
for(j=v[i];j<v[i+1];j++){
for(e=i-k+1;e>=0;e=e-k)
ans.push_back(make_pair(2,e));
if (i%k!=k-1)
r[i%k]--;
}
for(i=k-3;i>=0;i--)
r[i]=r[i]+r[i+1];
for(i=0;i<n;i++){
while(1){
if (r[i]>=0)
break;
ans.push_back(make_pair(1,i));
r[i]+=k;
}
}
if (n%k>=1 && r[0]<r[k-1]){
for(i=0;i<n%k;i++)
ans.push_back(make_pair(1,i)),r[i]+=k;
}
if (n%k){
for(i=n-k;i>=0;i=i-k)
for(j=0;j<r[0]-r[k-1];j++)
ans.push_back(make_pair(2,i));
}
printf("%d\n",ans.size());
for(i=0;i<ans.size();i++)
printf("%d %d\n",ans[i].first,ans[i].second+1);
return 0;
}
Compilation message (stderr)
# | 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... |