結果

問題 No.59 鉄道の旅
ユーザー NotationNapNotationNap
提出日時 2015-05-22 00:35:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 1,152 ms
コンパイル使用メモリ 144,512 KB
実行使用メモリ 7,872 KB
最終ジャッジ日時 2023-08-26 05:39:16
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 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 20 ms
7,872 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 7 ms
7,428 KB
testcase_09 AC 8 ms
7,236 KB
testcase_10 AC 8 ms
7,156 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 16 ms
6,368 KB
testcase_14 AC 16 ms
6,332 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))

const int SIZE = 1000000 + 10;
int bit[SIZE+1];
int get(int idx) {
	int sum = 0;
	for (int x = idx + 1; x > 0; x -= x & -x) sum += bit[x];
	return sum;
}
void add(int idx, int val) {
	for (int x = idx + 1; x <= SIZE; x += x & -x) bit[x] += val;
}

int W[100000];

int main() {
	int N, K; scanf("%d%d", &N, &K);
	REP(i, N) scanf("%d", W + i);

	int CO = 1000000 + 1;
	REP(n, N) {
		int w = W[n];
		if (w > 0) {
			if (get(CO - w) < K) {
				add(CO - w, 1);
			}
		}
		else {
			w = -w;
			if (get(CO - w) - get(CO - w - 1) > 0) {
				add(CO - w, -1);
			}
		}
	}
	cout << get(SIZE) << endl;

}
0