結果
| 問題 | No.365 ジェンガソート | 
| コンテスト | |
| ユーザー |  mannshi222 | 
| 提出日時 | 2019-07-13 21:43:18 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,925 bytes | 
| コンパイル時間 | 431 ms | 
| コンパイル使用メモリ | 30,336 KB | 
| 実行使用メモリ | 10,624 KB | 
| 最終ジャッジ日時 | 2024-11-22 15:46:16 | 
| 合計ジャッジ時間 | 57,478 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 TLE * 17 | 
ソースコード
#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;
}
            
            
            
        