結果

問題 No.59 鉄道の旅
ユーザー 6soukiti296soukiti29
提出日時 2017-08-02 19:56:57
言語 Nim
(2.0.2)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 931 bytes
コンパイル時間 3,003 ms
コンパイル使用メモリ 68,320 KB
実行使用メモリ 18,828 KB
最終ジャッジ日時 2023-09-12 13:51:48
合計ジャッジ時間 4,144 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 57 ms
18,828 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 24 ms
18,488 KB
testcase_09 AC 19 ms
15,904 KB
testcase_10 AC 20 ms
15,600 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 26 ms
4,376 KB
testcase_13 AC 34 ms
4,460 KB
testcase_14 AC 41 ms
4,712 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 26) Warning: imported and not used: 'math' [UnusedImport]

ソースコード

diff #

import strutils,sequtils,math

const
    x21 = 1 shl 21
    x20 = 1 shl 20

var
    N,K : int
    flag : array[100001,int]
    nimotu = newSeq[int](0)
    BIT : array[x21,int]
    cnt,w,index : int

(N,K) = stdin.readline.strip.split.map(parseInt)

proc hantei(i : int):bool=
    var
        j = i
        cnt = BIT[i]
    while (j and (j + 1)) > 0:
        if (j and 1) == 1:
            j = (j + 1) shr 1
            cnt += BIT[j]
        else:
            j += 1
            cnt += BIT[j]
    return cnt < K


for n in 1..N:
    w = stdin.readline.parseInt
    if w > 0:
        index = x20 + w
        if hantei(index):
            while index > 0:
                BIT[index] += 1
                index = index shr 1
            cnt += 1
    else:
        index = x20 - w
        if BIT[index] > 0:
            while index > 0:
                BIT[index] -= 1
                index = index shr 1
            cnt -= 1
echo cnt

0