結果

問題 No.885 アマリクエリ
ユーザー 6soukiti296soukiti29
提出日時 2019-09-13 22:33:02
言語 Nim
(2.0.2)
結果
AC  
実行時間 715 ms / 2,000 ms
コード長 1,805 bytes
コンパイル時間 3,219 ms
コンパイル使用メモリ 69,608 KB
実行使用メモリ 28,588 KB
最終ジャッジ日時 2023-09-17 14:50:50
合計ジャッジ時間 7,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 715 ms
25,956 KB
testcase_01 AC 350 ms
26,064 KB
testcase_02 AC 220 ms
27,988 KB
testcase_03 AC 194 ms
28,588 KB
testcase_04 AC 194 ms
26,788 KB
testcase_05 AC 183 ms
24,164 KB
testcase_06 AC 176 ms
26,708 KB
testcase_07 AC 28 ms
13,172 KB
testcase_08 AC 161 ms
13,544 KB
testcase_09 AC 352 ms
26,260 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(22, 25) Warning: Number of spaces around '<=' is not consistent [Spacing]

ソースコード

diff #

import sequtils,strutils,math
type
    priorityQue[I:static[int];T:tuple] = array[I + 1,T]
    item = tuple[cost: int]
proc push[T](A:var priorityQue; b: T;)=
    const key = 0
    A[0][0] += 1
    A[A[0][0]] = b # A[0][0]はsize、最大のIndex
    var index = A[0][0]
    while index > 1 and A[index][key] > A[index div 2][key]:
        (A[index],A[index div 2]) = (A[index div 2],A[index])
        index = index div 2
proc pop(A: var priorityQue):item =
    const key = 0
    result = A[1]
    A[1] = A[A[0][0]]
    var a : item
    A[A[0][0]] = a
    A[0][0] -= 1
    var index = 1
    while index * 2 <= A[0][0]:
        if index * 2 + 1<= A[0][0]:
            if A[index][key] < A[index * 2][key] and A[index * 2 + 1][key] <= A[index * 2][key]:
                (A[index],A[index * 2]) = (A[index * 2],A[index])
                index = index * 2
            elif A[index][key] < A[index * 2 + 1][key]:
                (A[index],A[index * 2 + 1]) = (A[index * 2 + 1],A[index])
                index = index * 2 + 1
            else:
                break
        elif index * 2 <= A[0][0]:
            if A[index][key] < A[index * 2][key]:
                (A[index],A[index * 2]) = (A[index * 2],A[index])
            break
        else:
            break
proc size(A : priorityQue):int=
    return A[0][0]

var
    N = stdin.readline.parseInt
    A = stdin.readline.split.map(parseInt)
    Q = stdin.readline.parseInt
    X = stdin.readline.split.map(parseInt)
    pq : priorityQue[200010, item]
    v = newSeq[item](0)
    S = sum(A)

for i,a in A:
    var p : item = (a,)
    pq.push(p)
    
for i,x in X:
    while pq.size > 0 and pq[1][0] >= x:
        var p = pq.pop
        S -= p.cost
        p.cost = p.cost mod x
        S += p.cost
        if p.cost > 0:
            pq.push(p)
    echo S
0