Submission #362505

#TimeUsernameProblemLanguageResultExecution timeMemory
362505denkendoemeerJOIRIS (JOI16_joiris)C++14
100 / 100
1 ms384 KiB
#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)

joiris.cpp: In function 'int main()':
joiris.cpp:63:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   63 |     printf("%d\n",ans.size());
      |             ~^    ~~~~~~~~~~
      |              |            |
      |              int          std::vector<std::pair<int, int> >::size_type {aka long unsigned int}
      |             %ld
joiris.cpp:64:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     for(i=0;i<ans.size();i++)
      |             ~^~~~~~~~~~~
joiris.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
joiris.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         scanf("%d",&v[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...