結果

問題 No.135 とりあえず1次元の問題
ユーザー しめはじめしめはじめ
提出日時 2019-07-12 15:02:54
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 728 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 28,148 KB
実行使用メモリ 5,292 KB
最終ジャッジ日時 2023-08-11 02:12:20
合計ジャッジ時間 1,395 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 14 ms
4,376 KB
testcase_22 WA -
evil01.txt AC 13 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘main’ 内:
main.c:16:16: 警告: iteration 1000000 invokes undefined behavior [-Waggressive-loop-optimizations]
   16 |         pos[i] = 'o';
      |         ~~~~~~~^~~~~
main.c:15:19: 備考: within this loop
   15 |     for( i = 0; i <= 1000000; i++ ){
      |                 ~~^~~~~~~~~~
main.c:16:16: 警告: ‘__builtin_memset’ writing 1000001 bytes into a region of size 1000000 overflows the destination [-Wstringop-overflow=]
   16 |         pos[i] = 'o';
      |         ~~~~~~~^~~~~
main.c:9:10: 備考: destination object ‘pos’ of size 1000000
    9 |     char pos[1000000];
      |          ^~~

ソースコード

diff #

#include <stdio.h>
int main(void){
    int n;
    scanf( "%d", &n );

    int i, j;
    int x;
    //int pos[n];
    char pos[1000000];
    int max = 0;
    long min = 1000000;
    int d = 0;
    int from = -1;

    for( i = 0; i <= 1000000; i++ ){
        pos[i] = 'o';
    }
    for( i = 0; i < n; i++ ){
        scanf( "%d", &x );
        pos[x] = 'x';
        if( x > max  ){
            max = x;
        }
    }

    for( i = 0; i <= max; i++ ){
        if( pos[i] == 'x' ){
            if( from < 0 ){
                from = i;
            }else{
                d = i - from;
                if( d > 0 && d < min ){
                    min = d;
                }
            }
        }
    }
    printf( "%d\n", min );
}
0