結果

問題 No.607 開通777年記念
ユーザー k1832k1832
提出日時 2021-07-01 18:27:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,360 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 102,656 KB
最終ジャッジ日時 2023-09-10 16:07:31
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,436 KB
testcase_01 AC 75 ms
71,056 KB
testcase_02 AC 75 ms
71,312 KB
testcase_03 WA -
testcase_04 AC 75 ms
71,104 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 125 ms
78,512 KB
testcase_08 AC 77 ms
71,064 KB
testcase_09 AC 88 ms
76,380 KB
testcase_10 AC 84 ms
76,180 KB
testcase_11 AC 284 ms
102,592 KB
testcase_12 AC 287 ms
102,656 KB
権限があれば一括ダウンロードができます

ソースコード

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(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