답안 #1091220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091220 2024-09-20T07:39:04 Z kolorvxl Giraffes (JOI22_giraffes) C
컴파일 오류
0 ms 0 KB
#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

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