結果

問題 No.489 株に挑戦
ユーザー roarisroaris
提出日時 2019-08-09 19:28:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,687 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 107,040 KB
最終ジャッジ日時 2023-09-26 13:21:13
合計ジャッジ時間 22,441 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 788 ms
99,360 KB
testcase_01 AC 692 ms
90,628 KB
testcase_02 AC 98 ms
71,764 KB
testcase_03 AC 98 ms
71,812 KB
testcase_04 AC 97 ms
71,812 KB
testcase_05 AC 97 ms
71,796 KB
testcase_06 AC 100 ms
72,272 KB
testcase_07 AC 99 ms
72,404 KB
testcase_08 AC 95 ms
71,672 KB
testcase_09 AC 110 ms
77,352 KB
testcase_10 AC 104 ms
76,764 KB
testcase_11 AC 103 ms
75,928 KB
testcase_12 AC 104 ms
76,736 KB
testcase_13 AC 103 ms
76,844 KB
testcase_14 AC 104 ms
76,760 KB
testcase_15 AC 238 ms
80,456 KB
testcase_16 TLE -
testcase_17 AC 294 ms
82,152 KB
testcase_18 AC 728 ms
84,676 KB
testcase_19 AC 705 ms
85,628 KB
testcase_20 TLE -
testcase_21 AC 460 ms
85,748 KB
testcase_22 AC 279 ms
82,364 KB
testcase_23 AC 634 ms
93,532 KB
testcase_24 TLE -
testcase_25 AC 103 ms
76,392 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 98 ms
71,780 KB
testcase_29 AC 97 ms
71,620 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 830 ms
94,420 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 655 ms
88,864 KB
testcase_36 AC 357 ms
82,696 KB
testcase_37 AC 759 ms
92,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

class SegmentTree:
    def __init__(self, N):
        n_ = 1
        while n_ < N:
            n_ *= 2
        self.n = n_
        self.arr = [-10 ** 18] * (2*self.n - 1)
    
    def update(self, k, a):
        k += self.n - 1
        self.arr[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.arr[k] = max(self.arr[2*k + 1], self.arr[2*k + 2])
        
    def query_sub(self, a, b, k, l, r):
        if r <= a or b <= l:
            return -10 ** 18
        
        if a <= l and r <= b:
            return self.arr[k]
        else:
            vl = self.query_sub(a, b, 2*k + 1, l, (l+r) / 2)
            vr = self.query_sub(a, b, 2*k + 2, (l+r) / 2, r)
            return max(vl, vr)
    
    def query(self, a, b):
        return self.query_sub(a, b, 0, 0, self.n)

N, D, K = map(int, input().split())
x = [int(input()) for _ in range(N)]
seg_tree = SegmentTree(N)

for i in range(N):
    seg_tree.update(i, x[i])
    
dic = defaultdict(list)

for i in range(N):
    dic[x[i]].append(i)

ans1 = -10 ** 18

for i in range(N-D):
    m = seg_tree.query(i, i+D+1)
    
    if m - x[i] <= ans1:
        continue
    else:
        ans1 = m - x[i]
        ans2 = i
        
        for l_i in dic[m]:
            if i <= l_i:
                ans3 = l_i
                break

for i in range(N-D+1, N):
    m = seg_tree.query(i, N)
    
    if m - x[i] <= ans1:
        continue
    else:
        ans1 = m - x[i]
        ans2 = i
        
        for l_i in dic[m]:
            if i <= l_i:
                ans3 = l_i
                break
            
if ans1 == 0:
    print(0)
else:
    print(ans1 * K)
    print(ans2, ans3)
0