結果

問題 No.135 とりあえず1次元の問題
ユーザー ksomemoksomemo
提出日時 2017-10-22 15:26:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 706 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 20,804 KB
最終ジャッジ日時 2024-05-01 10:16:32
合計ジャッジ時間 1,583 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 55 ms
20,788 KB
testcase_22 WA -
evil01.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    X = [int(x) for x in input().split()]

    # solve1(N, X)
    solve2(N, X)


def solve1(N, X):
    # 10^5 ^ 2 = 10^10, TLEしそう
    ans = float("inf")
    for i, x1 in enumerate(X):
        for x2 in X[i + 1:]:
            ans = min(ans, abs(x1 - x2))

    if ans == float("inf"):
        print(0)
    else:
        print(ans)


def solve2(N, X):
    # sortしてから引けばよさそう
    ans = float("inf")
    for i, x1 in enumerate(X[-1:], 1):
        x2 = X[i]
        if x1 == x2:
            continue
        ans = min(ans, abs(x1 - x2))

    if ans == float("inf"):
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()
0