답안 #1009732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1009732 2024-06-28T02:03:46 Z kolorvxl Giraffes (JOI22_giraffes) C
0 / 100
0 ms 348 KB
#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

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]);
      |         ^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -