結果

問題 No.365 ジェンガソート
ユーザー mannshi222mannshi222
提出日時 2019-07-13 21:43:18
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 2,925 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-02 04:55:21
合計ジャッジ時間 4,376 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,452 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ENDD '\0'
#define KIGY '\n'

#define TRUE 0
#define FALSE 1

int compare_int(const void *a, const void *b);

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main()
{
        int ch;
        char buff[100000+1];
        int buffi;
        int N;
        int *jen;
        int *jennext;
        int jeni;

        buffi = 0;
        while( (ch=getc(stdin)) != KIGY) {
                buff[buffi++] = ch;
        }
        buff[buffi] = ENDD;
        N = atoi(buff);

        buffi=0;
        jeni=0;
        jen = (int *)malloc((sizeof(int))*N);
        while( (ch=getc(stdin)) != EOF) {
                        if( ch==' ' ||  ch==KIGY   ) {
                                buff[buffi] = ENDD;
                                jen[jeni++] = atoi(buff);
                                buffi = 0;
                        }
                        else {
                                buff[buffi++] = ch;
                        }
        }

        /* search max */
        int smax;
        int count  = 0;
        int flg = FALSE;
        for( smax = N; smax >1 ; smax-- ) {

                if( flg == FALSE ) {
                        /* 一番数字が大きいものを探す */
                        jeni = N-1;
                        while( jen[jeni] != smax ){
                                jeni--;
                        }

                        /* 一番右側に一番大きい数字がある場合 */
                        if( jeni == smax-1 ) {
                                continue;
                        }

                        /* 一番右側にない場合 */

                }
                else {
                        jeni = 0;
                }

                /* 次に大きい数字を探す */
                int jenii;
                jenii = N-1;
                while( jen[jenii] != smax-1 ){
                        jenii--;
                }

                /* 一番大きいものの左に二番目に大きいものがある場合はなにもしない */
                if( jenii < jeni ) {
                        flg=FALSE;
                        continue;
                }

                /* 一番大きいものの右に二番目に大きいものがある場合は */
                /* 二番目に大きいものを一番左にいどうする */
                count++;
                flg=TRUE;
                jennext = (int *)malloc((sizeof(int))*N);
                jennext[0]=jen[jenii];
                int j=0;
                for( int i = 1; i < N; i++ ) {
                        if( jen[j] == smax-1) {
                                j++;
                        }
                        jennext[i] = jen[j++];

                }
                free( jen );
                jen = jennext;

        }
        printf("%d\n", count );

        return 0;
}
0