結果

問題 No.59 鉄道の旅
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-18 01:41:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 2,479 ms
コンパイル使用メモリ 182,728 KB
実行使用メモリ 9,640 KB
最終ジャッジ日時 2023-08-26 06:55:04
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 54 ms
6,152 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 14 ms
4,384 KB
testcase_13 AC 62 ms
6,452 KB
testcase_14 AC 89 ms
9,640 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++)
#define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++)
#define all(n) (n).begin(),(n).end()
typedef long long ll;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<long long,long long> Pii;
typedef vector<Pii> VPii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> set2;
int main(){
	int N,K;
	cin >> N >> K;
	set2 S;

	rep(i,N){
		int W;
		cin >> W;
		if( W > 0 ){
			int num = S.size() - S.order_of_key({W,-1});
			if( num < K ){
				S.insert({W,i});
			}
		}else{
			W = -W;
			auto key = S.lower_bound({W,-1});
			if( key != S.end() && key->first == W ) S.erase(*key);
		}
	}
	cout << S.size() << endl;
}
0