結果

問題 No.489 株に挑戦
ユーザー rpy3cpprpy3cpp
提出日時 2017-03-26 22:16:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,364 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 23,388 KB
最終ジャッジ日時 2023-09-20 11:08:32
合計ジャッジ時間 5,561 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
14,920 KB
testcase_01 AC 127 ms
12,872 KB
testcase_02 AC 20 ms
8,656 KB
testcase_03 AC 20 ms
8,660 KB
testcase_04 AC 20 ms
8,552 KB
testcase_05 AC 20 ms
8,732 KB
testcase_06 AC 20 ms
8,728 KB
testcase_07 AC 19 ms
8,632 KB
testcase_08 AC 19 ms
8,720 KB
testcase_09 AC 20 ms
8,724 KB
testcase_10 AC 19 ms
8,692 KB
testcase_11 AC 19 ms
8,664 KB
testcase_12 AC 20 ms
8,564 KB
testcase_13 AC 20 ms
8,692 KB
testcase_14 AC 19 ms
8,752 KB
testcase_15 AC 30 ms
9,096 KB
testcase_16 AC 206 ms
15,772 KB
testcase_17 AC 47 ms
9,580 KB
testcase_18 AC 125 ms
12,912 KB
testcase_19 AC 104 ms
11,940 KB
testcase_20 AC 207 ms
16,152 KB
testcase_21 AC 66 ms
10,472 KB
testcase_22 AC 37 ms
9,224 KB
testcase_23 AC 136 ms
13,224 KB
testcase_24 AC 242 ms
17,100 KB
testcase_25 AC 20 ms
8,752 KB
testcase_26 AC 223 ms
13,924 KB
testcase_27 WA -
testcase_28 AC 19 ms
8,720 KB
testcase_29 AC 20 ms
8,704 KB
testcase_30 AC 237 ms
17,304 KB
testcase_31 AC 249 ms
23,388 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 49 ms
9,608 KB
testcase_37 AC 135 ms
12,936 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