結果

問題 No.489 株に挑戦
ユーザー rpy3cpprpy3cpp
提出日時 2017-03-26 22:46:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,363 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 23,340 KB
最終ジャッジ日時 2023-09-20 11:09:08
合計ジャッジ時間 5,403 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
14,952 KB
testcase_01 AC 127 ms
12,892 KB
testcase_02 AC 19 ms
8,656 KB
testcase_03 AC 18 ms
8,556 KB
testcase_04 AC 19 ms
8,552 KB
testcase_05 AC 18 ms
8,740 KB
testcase_06 AC 18 ms
8,592 KB
testcase_07 AC 18 ms
8,696 KB
testcase_08 AC 18 ms
8,520 KB
testcase_09 AC 19 ms
8,588 KB
testcase_10 AC 19 ms
8,728 KB
testcase_11 AC 19 ms
8,592 KB
testcase_12 AC 19 ms
8,672 KB
testcase_13 AC 19 ms
8,668 KB
testcase_14 AC 19 ms
8,604 KB
testcase_15 AC 30 ms
8,940 KB
testcase_16 AC 207 ms
15,596 KB
testcase_17 AC 48 ms
9,608 KB
testcase_18 AC 126 ms
12,816 KB
testcase_19 AC 104 ms
11,848 KB
testcase_20 AC 207 ms
16,084 KB
testcase_21 AC 65 ms
10,436 KB
testcase_22 AC 36 ms
9,412 KB
testcase_23 AC 136 ms
13,108 KB
testcase_24 AC 242 ms
17,100 KB
testcase_25 AC 19 ms
8,556 KB
testcase_26 AC 225 ms
14,040 KB
testcase_27 WA -
testcase_28 AC 19 ms
8,592 KB
testcase_29 AC 19 ms
8,672 KB
testcase_30 AC 240 ms
17,172 KB
testcase_31 AC 249 ms
23,340 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 47 ms
9,732 KB
testcase_37 AC 132 ms
13,048 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