結果

問題 No.489 株に挑戦
ユーザー rpy3cpprpy3cpp
提出日時 2017-03-26 22:44:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,365 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 87,400 KB
実行使用メモリ 88,168 KB
最終ジャッジ日時 2023-09-20 11:09:02
合計ジャッジ時間 7,733 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 172 ms
84,920 KB
testcase_01 AC 155 ms
82,144 KB
testcase_02 AC 95 ms
71,788 KB
testcase_03 AC 96 ms
71,864 KB
testcase_04 AC 93 ms
71,792 KB
testcase_05 AC 100 ms
71,732 KB
testcase_06 AC 97 ms
71,728 KB
testcase_07 AC 98 ms
71,968 KB
testcase_08 AC 96 ms
71,444 KB
testcase_09 AC 97 ms
71,428 KB
testcase_10 AC 97 ms
71,572 KB
testcase_11 AC 95 ms
71,764 KB
testcase_12 AC 96 ms
71,760 KB
testcase_13 AC 95 ms
71,728 KB
testcase_14 AC 96 ms
71,624 KB
testcase_15 AC 127 ms
78,240 KB
testcase_16 AC 170 ms
86,360 KB
testcase_17 AC 146 ms
78,620 KB
testcase_18 AC 155 ms
83,208 KB
testcase_19 AC 146 ms
81,432 KB
testcase_20 AC 170 ms
85,552 KB
testcase_21 AC 136 ms
78,812 KB
testcase_22 AC 136 ms
78,700 KB
testcase_23 AC 162 ms
82,108 KB
testcase_24 AC 175 ms
86,900 KB
testcase_25 AC 96 ms
71,980 KB
testcase_26 AC 170 ms
88,168 KB
testcase_27 RE -
testcase_28 AC 93 ms
71,800 KB
testcase_29 AC 96 ms
71,488 KB
testcase_30 AC 191 ms
86,988 KB
testcase_31 AC 168 ms
87,148 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 129 ms
77,952 KB
testcase_37 AC 156 ms
82,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

def read_data():
    N, D, K = map(int, input().split())
    xs = []
    for n in range(N):
        xs.append(int(input()))
    return N, D, K, xs


def solve(N, D, K, xs):
    maxval, first, last = solve_core(N, D, xs)
    if maxval:
        print(maxval * K)
        print(first, last)
    else:
        print(0)

def slide_min(Vs, w):
    '''ウインドウ幅 w でのスライド最小値のリストを返す。
    引数
     Vs: 数列
     w:  スライド幅を表す整数。w = 0 ならば、Vs を返す。w = 1 ならば、Vs[i] と Vs[i-1]のうち小さい方の入ったリストを返す。
    返り値
     Ms: Ms[i] = min(Vs[i-w:i+1]) を満たすリスト
    '''
    N = len(Vs)
    dq = collections.deque()
    Ms = [float('inf')] * N
    for i, v in enumerate(Vs):
        if dq:
            while dq and dq[-1][1] >= v:
                dq.pop()
        dq.append((i, v))
        if dq[0][0] + w < i:
            dq.popleft()
        pos, val = dq[0]
        Ms[i] = val
    return Ms

def solve_core(N, D, xs):
    Ms = slide_min(xs, D)
    Bs = [x - m for m, x in zip(Ms, xs)]
    b = max(Bs)
    sell = Bs.index(b)
    m = xs[sell] - b
    for p in range(max(sell - D, 0), sell + 1):
        if Ms[p] == m:
            buy = p
            break
    return b, buy, sell

N, D, K, xs = read_data()
solve(N, D, K, xs)
0