Submission #284142

# Submission time Handle Problem Language Result Execution time Memory
284142 2020-08-26T22:56:23 Z anonymous JOIRIS (JOI16_joiris) C++14
30 / 100
1 ms 384 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() {
    while (true) {
        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;
        }
        bool okay = true;
        for (int i=1; i<=N; i++) {
            if (A[i]) {
                okay = false;
                break;
            }
        }
        if (!okay) {
            for (int i=1; i<=N; i++) {
                if (!A[i]) {
                    vert(i);
                }
            }
        } else {
            return;
        }
    }
}


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+1; i++) {
        Sum[(i+K-1)%K] = (Sum[(i+K-1)%K] + A[i]-A[i-1] + K ) % K;
    }
    for (int i=1; i<K; i++) {
        if (Sum[i]) {
            printf("-1");
            return(0);
        }
    }

    for (int i=N; 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

joiris.cpp: In function 'int main()':
joiris.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |     scanf("%d %d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~
joiris.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         scanf("%d",&A[i]);
      |         ~~~~~^~~~~~~~~~~~
# 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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 0 ms 256 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
# 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 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Incorrect 0 ms 256 KB Output isn't correct
18 Halted 0 ms 0 KB -