Submission #276759

#TimeUsernameProblemLanguageResultExecution timeMemory
276759limabeansJOIRIS (JOI16_joiris)C++17
0 / 100
1 ms512 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl const int VERT = 1; const int HORZ = 2; using ll = long long; const ll mod = 1e9+7; const int maxn = 55; int n, k; int a[maxn]; vector<pair<int,int>> moves; void insert(int dir, int i) { moves.push_back({dir, i}); if (dir==VERT) { a[i] += k; } else { assert(i+k-1<=n); for (int j=i; j<i+k; j++) { a[j]++; } } } void relax() { int lo = 1e9; for (int i=1; i<=n; i++) { lo = min(lo, a[i]); } for (int i=1; i<=n; i++) { a[i] -= lo; } } bool finished() { for (int i=1; i<=n; i++) { if (a[i]>0) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>k; for (int i=1; i<=n; i++) { cin>>a[i]; } assert(k==2 && n%2==0); //subtask1 while (!finished()) { int mx = 0; for (int i=1; i<=n; i++) { mx = max(mx, a[i]); } if (mx > 1) { for (int i=1; i<=n; i++) { if (a[i]==0) { insert(VERT, i); } } relax(); } else { // all 0 sections need to be even for (int i=1; i<=n; ) { if (a[i]==1) { i++; continue; } int j=i; while (j<=n && a[j]==0) { j++; } int len = j-i; if (len%2==1) { out(-1); } else { for (int x=i; x<j; x+=k) { insert(HORZ, x); } } i=j; } break; } } const int LIMIT = 1e4; assert((int)moves.size() <= LIMIT); cout<<moves.size()<<"\n"; for (auto p: moves) { cout<<p.first<<" "<<p.second<<"\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...