Submission #1091220

#TimeUsernameProblemLanguageResultExecution timeMemory
1091220kolorvxlGiraffes (JOI22_giraffes)C11
Compilation error
0 ms0 KiB
#include <stdio.h>int n;int arr[302];int cost[302][302][302] = {0};void apply(int *a, int b) { if (*a > b) { *a = b; }}int get_cost(int start, int end, int offset) { if (end == start) { return arr[start - 1] != (offset + 1); } if (cost[start][end][offset] == -1) { int length = end - start + 1; int min = offset + 1; int max = length + offset; int costtmp = 10000; apply(&costtmp, get_cost(start + 1, end, offset + 1) + (min != arr[start- 1])); apply(&costtmp, get_cost(start + 1, end, offset) + (max != arr[start- 1])); apply(&costtmp, get_cost(start, end - 1, offset + 1) + (min != arr[end- 1])); apply(&costtmp, get_cost(start, end - 1, offset) + (max != arr[end- 1])); cost[start][end][offset] = costtmp; // printf("%d %d %d %d %d\n", start, end, min, max, costtmp); } return cost[start][end][offset];}int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) { for (int k = 0; k < n + 1; k++) { cost[i][j][k] = -1; } } } printf("%d", get_cost(1, n, 0)); return 0;}

Compilation message (stderr)

giraffes.c:1:19: warning: extra tokens at end of #include directive
    1 | #include <stdio.h>int n;int arr[302];int cost[302][302][302] = {0};void apply(int *a, int b) {    if (*a > b) {        *a = b;    }}int get_cost(int start, int end, int offset) {    if (end == start) {        return arr[start - 1] != (offset + 1);    }        if (cost[start][end][offset] == -1) {        int length = end - start + 1;        int min = offset + 1;        int max = length + offset;                 int costtmp = 10000;                apply(&costtmp, get_cost(start + 1, end, offset + 1) + (min != arr[start- 1]));        apply(&costtmp, get_cost(start + 1, end, offset) + (max != arr[start- 1]));        apply(&costtmp, get_cost(start, end - 1, offset + 1) + (min != arr[end- 1]));        apply(&costtmp, get_cost(start, end - 1, offset) + (max != arr[end- 1]));                cost[start][end][offset] = costtmp;        // printf("%d %d  %d %d   %d\n", start, end, min, max, costtmp);    }        return cost[start][end][offset];}int main() {    scanf("%d", &n);    for (int i = 0; i < n; i++) {        scanf("%d", &arr[i]);    }        for (int i = 0; i < n + 1; i++) {        for (int j = 0; j < n + 1; j++) {            for (int k = 0; k < n + 1; k++) {                cost[i][j][k] = -1;            }        }    }        printf("%d", get_cost(1, n, 0));        return 0;}
      |                   ^~~
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status