# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284970 | 2020-08-28T08:36:16 Z | anonymous | JOIRIS (JOI16_joiris) | C++14 | 1 ms | 256 KB |
#include <iostream> #define MAXN 55 using namespace std; int N, K, A[MAXN], Sum[MAXN]; //4N^2 operations int Q, Ops[MAXN * MAXN * 4][2]; void hor(int x) { for (int i=x; i<x+K; i++) { A[i] += 1; } Ops[Q][0] = 2, Ops[Q][1] = x; Q++; } void vert(int x) { A[x] += K; Ops[Q][0] = 1, Ops[Q][1] = x; Q++; } void op1(int x) { while (true) { int maxh = 0; for (int i=x; i<x+K; i++) { maxh = max(maxh, A[i]); } bool good = true; for (int i=1; i<=N; i++) { if ((i < x || i >= x+K) && A[i] <= maxh) { vert(i); good = false; } } if (good) { hor(x); return; } } } void finish() { int minh = 1<<30; for (int i=1; i<=N; i++) { minh = min(minh, A[i]); } for (int i=1; i<=N; i++) { A[i] -= minh; } int maxh = 0; for (int i=1; i<=N; i++) { maxh = max(maxh, A[i]); } for (int i=1; i<=N; i++) { for (int j=1; j <= (maxh-A[i])/K; j++) { vert(i); } } } int main() { //freopen("joirisin.txt","r",stdin); scanf("%d %d",&N,&K); for (int i=1; i<=N; i++) { scanf("%d",&A[i]); } for (int i=1; i<N; i++) { Sum[i%K] = (Sum[i%K] + A[i+1] - A[i] + K) % K; } while (N > K && Sum[N%K]) { op1(N-K+1), Sum[N%K]=(Sum[N%K]+1)%K; } while (N > K && Sum[0]) { op1(1), Sum[0]=(Sum[0]+K-1)%K; } for (int i=-0; i<K; i++) { if (Sum[i]) { printf("-1\n"); return(0); } } for (int i=N-1; i>=K; i--) { while ((A[i+1]-A[i])%K) {op1(i-K+1);} } finish(); printf("%d\n",Q); for (int i=0; i<Q; i++) { printf("%d %d\n",Ops[i][0], Ops[i][1]); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Incorrect | 0 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Incorrect | 0 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Incorrect | 0 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |