結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
14,956 KB
testcase_01 AC 61 ms
12,808 KB
testcase_02 AC 20 ms
8,592 KB
testcase_03 AC 19 ms
8,516 KB
testcase_04 RE -
testcase_05 AC 19 ms
8,560 KB
testcase_06 AC 19 ms
8,560 KB
testcase_07 AC 19 ms
8,548 KB
testcase_08 AC 19 ms
8,708 KB
testcase_09 AC 19 ms
8,592 KB
testcase_10 AC 20 ms
8,592 KB
testcase_11 AC 19 ms
8,560 KB
testcase_12 AC 20 ms
8,544 KB
testcase_13 AC 19 ms
8,724 KB
testcase_14 AC 19 ms
8,608 KB
testcase_15 AC 23 ms
8,948 KB
testcase_16 AC 86 ms
15,804 KB
testcase_17 AC 29 ms
9,660 KB
testcase_18 AC 58 ms
12,812 KB
testcase_19 AC 51 ms
12,008 KB
testcase_20 AC 87 ms
16,088 KB
testcase_21 AC 36 ms
10,472 KB
testcase_22 AC 25 ms
9,204 KB
testcase_23 AC 61 ms
13,212 KB
testcase_24 AC 99 ms
17,236 KB
testcase_25 AC 19 ms
8,708 KB
testcase_26 AC 87 ms
13,924 KB
testcase_27 WA -
testcase_28 AC 19 ms
8,536 KB
testcase_29 AC 19 ms
8,552 KB
testcase_30 AC 100 ms
17,136 KB
testcase_31 AC 110 ms
23,328 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 30 ms
9,732 KB
testcase_37 AC 62 ms
13,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import sys

def read_data():
    N, D, K = map(int, input().split())
    xs = []
    for line in sys.stdin:
        xs.append(int(line))
    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