Submission #1009732

#TimeUsernameProblemLanguageResultExecution timeMemory
1009732kolorvxlGiraffes (JOI22_giraffes)C11
0 / 100
0 ms348 KiB
#include <stdio.h> #include <stdlib.h> int cost(int l, int *arr) { if (l <= 3) { return 0; } int *iarr; iarr = (int*)malloc(sizeof(int) * l); for (int i = 0; i < l; i++) { iarr[i] = arr[i]; // printf("%d ", iarr[i]); } // printf("\n"); int max = 0; int maxi = 0; int min = 10000; int mini = 0; for (int i = 0; i < l; i++) { if (max < iarr[i]) { max = iarr[i]; maxi = i; } if (min > iarr[i]) { min = iarr[i]; mini = i; } } if (mini == 0 || maxi == 0) { int v = cost(l - 1, iarr + 1); free(iarr); return v; } if (mini == l - 1 || maxi == l - 1) { int v = cost(l - 1, iarr); free(iarr); return v; } int v = 10000; int k = 0; int a, b, t; a = 0; b = mini; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; k = cost(l - 1, iarr + 1); if (v > k) v = k; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; a = 0; b = maxi; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; k = cost(l - 1, iarr + 1); if (v > k) v = k; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; a = l - 1; b = mini; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; k = cost(l - 1, iarr); if (v > k) v = k; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; a = l - 1; b = maxi; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; k = cost(l - 1, iarr); if (v > k) v = k; t = iarr[a]; iarr[a] = iarr[b]; iarr[b] = t; free(iarr); return v + 1; } int main() { int n; int arr[13]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } printf("%d", cost(n, arr) * 2); return 0; }

Compilation message (stderr)

giraffes.c: In function 'main':
giraffes.c:88:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     scanf("%d", &n);
      |     ^~~~~~~~~~~~~~~
giraffes.c:90:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         scanf("%d", &arr[i]);
      |         ^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...