結果

問題 No.59 鉄道の旅
ユーザー 6soukiti296soukiti29
提出日時 2017-08-02 19:51:32
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 929 bytes
コンパイル時間 5,930 ms
コンパイル使用メモリ 68,172 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-12 13:51:34
合計ジャッジ時間 4,501 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import strutils,sequtils,math

const
    x18 = 1 shl 18
    x17 = 1 shl 17

var
    N,K : int
    flag : array[100001,int]
    nimotu = newSeq[int](0)
    BIT : array[x18,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 = x17 + w
        if hantei(index):
            while index > 0:
                BIT[index] += 1
                index = index shr 1
            cnt += 1
    else:
        index = x17 - w
        if BIT[index] > 0:
            while index > 0:
                BIT[index] -= 1
                index = index shr 1
            cnt -= 1
echo cnt
0