結果

問題 No.1079 まお
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-06-12 22:53:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 135,372 KB
最終ジャッジ日時 2023-09-06 11:03:06
合計ジャッジ時間 7,606 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,816 KB
testcase_01 AC 95 ms
71,800 KB
testcase_02 AC 94 ms
71,604 KB
testcase_03 AC 92 ms
71,740 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 175 ms
107,028 KB
testcase_13 AC 194 ms
114,028 KB
testcase_14 AC 204 ms
118,988 KB
testcase_15 AC 218 ms
123,184 KB
testcase_16 AC 231 ms
128,396 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 263 ms
133,708 KB
testcase_23 AC 263 ms
133,840 KB
testcase_24 AC 267 ms
133,700 KB
testcase_25 AC 262 ms
134,028 KB
testcase_26 AC 251 ms
133,980 KB
testcase_27 AC 136 ms
90,628 KB
testcase_28 AC 197 ms
115,816 KB
testcase_29 AC 183 ms
135,372 KB
testcase_30 AC 188 ms
135,344 KB
testcase_31 AC 149 ms
91,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys;input=sys.stdin.readline
from collections import defaultdict
n, k = map(int, input().split())
X = list(map(int, input().split()))
st_f = [(0, 10**18), (X[0], X[0])]
st_b = [(0, 10**18)]
r = 0
j = 1
C = defaultdict(int)
D = defaultdict(int)
C[X[0]] += 1
D[X[0]] += 1
for i in range(n):
    while j<n:
#        if j == n:
#            j += 1
#            break
        if min(st_f[-1][1], st_b[-1][1]) == X[j]:
            break
        C[X[j]] += j+1
        D[X[j]] += 1
        st_f.append(
                (X[j], min(st_f[-1][1], X[j]))
                )
        j += 1
    if len(st_b) == 1:
        while len(st_f) > 1:
            x, y = st_f.pop()
            st_b.append(
                    (x, min(st_b[-1][1], x))
                    )
    st_b.pop()
    r += C[k-X[i]] - D[k-X[i]]*i
#    print(i, j, C[k-X[i]], D[k-X[i]])
    C[X[i]] -= i+1
    D[X[i]] -= 1
print(r)
0