結果

問題 No.360 増加門松列
ユーザー yfujita0929yfujita0929
提出日時 2016-04-18 00:09:05
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 2,557 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 26,112 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 18:36:33
合計ジャッジ時間 1,767 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 0 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 0 ms
4,380 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

#define SIZE 7

void swap(int shift, int *arr, int size);
void sort(int *arr, int size);
int max(int a, int b, int c);
int min(int a, int b, int c);
int isIncKadomatsu(int a, int b, int c);

int main(void)
{
    char *str;
    int *d, idx, cnt = 0;
    
    str = (char*)calloc(sizeof(char), 4);
    d = (int*)calloc(sizeof(int), SIZE);
    for(idx = 0; idx < SIZE; idx++) {
        scanf("%d", &d[idx]);
    }
    
    sort(d, SIZE);
    swap(0, d, SIZE);
    /*
    for(idx = 0; idx < SIZE; idx++) {
        printf("%d ", d[idx]);
    }
    printf("\n");
    */
    for(idx = 0; idx < (SIZE-2); idx++) {
        if( isIncKadomatsu(d[idx], d[(idx+1)], d[(idx+2)]) ) {
            cnt++;
        }
    }
    if(cnt == (SIZE-2)) {
        printf("YES\n");
        return 0;
    }
    
    cnt = 0;
    sort(d, SIZE);
    swap(1, d, SIZE);
    /*
    for(idx = 0; idx < SIZE; idx++) {
        printf("%d ", d[idx]);
    }
    printf("\n");
    */
    for(idx = 0; idx < (SIZE-2); idx++) {
        if( isIncKadomatsu(d[idx], d[(idx+1)], d[(idx+2)]) ) {
            cnt++;
        }
    }
    if(cnt == (SIZE-2)) {
        printf("YES\n");
        return 0;
    }
    
    printf("NO\n");
    
    free(str);
    free(d);
    return 0;
}

void swap(int shift, int *arr, int size) {
    int idx, tmp;
    
    for(idx = shift; idx <= (size-3+shift); idx += 2) {
        tmp = arr[idx];
        arr[idx] = arr[(idx+1)];
        arr[(idx+1)] = tmp;
    }
}

void sort(int *arr, int size)
{
    int i, j, tmp;
    
    for(i = 0; i < size; i++) {
        for(j = i+1; j < size; j++) {
            if(arr[i] > arr[j]) {
                tmp = arr[j];
                arr[j] = arr[i];
                arr[i] = tmp;
            }
        }
    }
}

int max(int a, int b, int c)
{
    if(a > b) {
        if(a > c) {
            return a;
        }
        else {
            return c;
        }
    }
    else {
        if(b > c) {
            return b;
        }
        else {
            return c;
        }
    }
}

int min(int a, int b, int c)
{
    if(a > b) {
        if(b > c) {
            return c;
        }
        else {
            return b;
        }
    }
    else {
        if(a > c) {
            return c;
        }
        else {
            return a;
        }
    }
}

int isIncKadomatsu(int a, int b, int c)
{
    if (a == b || b == c || c == a) {
        return 0;
    }
    
    if (max(a, b, c) == b || min(a, b, c) == b) {
        if (a < c) {
            return 1;
        }
    }
    
    return 0;
}
0