結果

問題 No.607 開通777年記念
ユーザー k1832k1832
提出日時 2021-07-01 18:28:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,363 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 130,652 KB
最終ジャッジ日時 2023-09-10 16:08:47
合計ジャッジ時間 4,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,564 KB
testcase_01 AC 16 ms
7,824 KB
testcase_02 AC 16 ms
8,168 KB
testcase_03 AC 15 ms
8,220 KB
testcase_04 AC 16 ms
7,896 KB
testcase_05 AC 15 ms
8,132 KB
testcase_06 AC 16 ms
8,132 KB
testcase_07 AC 448 ms
16,608 KB
testcase_08 AC 16 ms
7,764 KB
testcase_09 AC 45 ms
9,288 KB
testcase_10 AC 26 ms
9,092 KB
testcase_11 TLE -
testcase_12 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# Should not work in the time limit.
N, M = list(map(int, input().split()))
inc_dec = []
for _ in range(M):
    inc_dec.append(list(map(int, input().split())))

# num_passengers[i][j]: i駅時点でのj番目の車両の乗客数
num_passengers = [[0] * N for _ in range(M)]
# cum_sum[i][j+1]: i駅の時点での、0番目の車両からj番目の車両までの総乗客数
cum_sum = [[0] * (N+1) for _ in range(M)]

for j in range(N):
    num_passengers[0][j] = inc_dec[0][j]
    cum_sum[0][j+1] = cum_sum[0][j] + num_passengers[0][j]

for i in range(1, M):
    for j in range(N):
        num_passengers[i][j] = num_passengers[i-1][j] + inc_dec[i][j]
        cum_sum[i][j+1] = cum_sum[i][j] + num_passengers[i][j]

for station in range(M):
    for start_i in range(N):
        target = 777 + cum_sum[station][start_i]
        # 以下のようになるようなxを求める
        # cum_sum[station][x] - cum_sum[station][start_i] == 777

        # xの候補の範囲
        l, r = start_i+1, N
        while l < r:
            m = (l + r) // 2
            if cum_sum[station][m] == target:
                print('YES')
                exit()
            if cum_sum[station][m] < target:
                l = m + 1
            else:
                r = m - 1
        if cum_sum[station][l] == target:
            print('YES')
            exit()
print('NO')
0