# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1091220 | kolorvxl | Giraffes (JOI22_giraffes) | C11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;}