結果

問題 No.59 鉄道の旅
ユーザー kou6839kou6839
提出日時 2014-12-19 19:38:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 73,732 KB
実行使用メモリ 75,384 KB
最終ジャッジ日時 2023-08-26 05:34:47
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
66,192 KB
testcase_01 AC 125 ms
65,088 KB
testcase_02 AC 122 ms
65,104 KB
testcase_03 AC 124 ms
65,584 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 127 ms
63,432 KB
testcase_08 AC 260 ms
73,708 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 542 ms
75,384 KB
testcase_14 AC 491 ms
74,804 KB
testcase_15 AC 120 ms
65,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
class BIT{
	int[] bit=new int[2000001];
    void add(int a,int w){;
    	for(int x = a;x<=2000000;x+=(x&-x)) {
    		bit[x] += w;
    	}
    }
    int sum(int a){
    	int ret = 0;
    	for(int x = a;x>0;x -= x& -x) ret += bit[x];
    	return ret;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int k = sc.nextInt();
        BIT bit = new BIT();
        int[] aru = new int[1000001];
    	int ans=0;
        for(int i=0;i<n;i++){
        	int temp = sc.nextInt();
        	if(temp>0){
        		if( (bit.sum(2000000)-bit.sum(temp))>=k) continue;
        		bit.add(temp,1);
        		aru[temp]++;
        		ans++;
        	}else{
        		if(aru[-temp]>0) {
        			ans--;
        			bit.add(-temp,-1);
        		}
        	}
        }
        System.out.println(ans);
    }
}		
0