結果

問題 No.343 手抜き工事のプロ
ユーザー rpy3cpprpy3cpp
提出日時 2016-02-12 22:51:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 11,768 KB
実行使用メモリ 17,792 KB
最終ジャッジ日時 2023-10-22 03:18:33
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,024 KB
testcase_01 AC 30 ms
10,024 KB
testcase_02 AC 30 ms
10,024 KB
testcase_03 AC 30 ms
10,024 KB
testcase_04 AC 29 ms
10,024 KB
testcase_05 AC 30 ms
10,024 KB
testcase_06 AC 30 ms
10,024 KB
testcase_07 AC 30 ms
10,024 KB
testcase_08 AC 29 ms
10,024 KB
testcase_09 AC 30 ms
10,024 KB
testcase_10 AC 30 ms
10,024 KB
testcase_11 AC 31 ms
10,024 KB
testcase_12 AC 31 ms
10,028 KB
testcase_13 AC 57 ms
10,668 KB
testcase_14 AC 34 ms
10,064 KB
testcase_15 AC 32 ms
10,064 KB
testcase_16 AC 30 ms
10,024 KB
testcase_17 AC 30 ms
10,024 KB
testcase_18 AC 30 ms
10,024 KB
testcase_19 AC 30 ms
10,024 KB
testcase_20 AC 57 ms
10,776 KB
testcase_21 AC 117 ms
12,596 KB
testcase_22 AC 147 ms
12,220 KB
testcase_23 AC 197 ms
14,972 KB
testcase_24 AC 253 ms
16,404 KB
testcase_25 AC 293 ms
17,792 KB
testcase_26 AC 287 ms
17,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N = int(input())
    L = int(input())
    Xs = [int(input()) for i in range(N - 1)]
    return N, L, Xs

def solve(N, L, Xs):
    Xs.reverse()
    Xs.append(0)
    cum = 0
    n = 0
    centers = []
    for x in Xs:
        cum += x
        n += 1
        center = (cum / n) + L/2
        centers.append(center)
    bonds = 0
    for i in range(N-1):
        center = centers[i]
        x_top = Xs[i]
        x_bottom = Xs[i + 1]
        left = max(x_top, x_bottom)
        right = min(x_top + L, x_bottom + L)
        if left >= right:
            return -1
        if left < center < right:
            pass
        else:
            bonds += 1
    return bonds

N, L, Xs = read_data()
print(solve(N, L, Xs))
0