結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  6soukiti29 | 
| 提出日時 | 2017-09-02 17:08:49 | 
| 言語 | Nim (2.2.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 31 ms / 5,000 ms | 
| コード長 | 2,185 bytes | 
| コンパイル時間 | 2,997 ms | 
| コンパイル使用メモリ | 66,520 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-30 03:06:37 | 
| 合計ジャッジ時間 | 3,511 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
コンパイルメッセージ
/home/judge/data/code/Main.nim(22, 25) Warning: Number of spaces around '<=' is not consistent [Spacing]
ソースコード
import sequtils,strutils,algorithm
type
    priorityQue[I:static[int];T:tuple] = array[I + 1,T]
    item = tuple[cost: int,ID : 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]]
    A[A[0][0]] = (0,0)
    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
    T = stdin.readline.parseInt
for t in 1..T:
    var
        N = stdin.readline.parseInt
        T = stdin.readline.split.map(parseInt)
        i : int
        cnt : int
        ans : int
        a,b,c : item
        A : array[101, item]
        PQ : priorityque[101, item]
    T.sort(system.cmp)
    for j,t in T:
        if j == 0:
            cnt += 1
        elif T[j - 1] != t:
            A[i] = (cnt, i)
            cnt = 1
            i += 1
        else:
            cnt += 1
    A[i] = (cnt,i)
    for a in A[0..i]:
        PQ.push(a)
    while PQ.size > 2:
        a = PQ.pop()
        b = PQ.pop()
        c = PQ.pop()
        a.cost -= 1
        b.cost -= 1
        c.cost -= 1
        ans += 1
        if a.cost > 0:
            PQ.push(a)
        if b.cost > 0:
            PQ.push(b)
        if c.cost > 0:
            PQ.push(c)
    echo ans
            
            
            
        