結果

問題 No.59 鉄道の旅
ユーザー ano184ano184
提出日時 2014-11-08 03:39:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,045 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 75,072 KB
実行使用メモリ 7,608 KB
最終ジャッジ日時 2023-08-26 05:30:53
合計ジャッジ時間 1,996 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 126 ms
7,608 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 29 ms
7,288 KB
testcase_09 AC 17 ms
7,108 KB
testcase_10 AC 28 ms
6,680 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 27 ms
4,376 KB
testcase_13 AC 42 ms
4,376 KB
testcase_14 AC 55 ms
4,376 KB
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>

#define rep(x,to) for(int (x)=(0);(x)<(to);(x)++)
#define repf(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)

using namespace std;

const int MX=1000000;
int zmp[MX+10];
int main()
{
	int n, k;
	const int gsz=200;
	cin >> n >>k;
	vector<int> w(n);
	repf(i,0,n) cin >>w[i];
	//map<unsigned int,int> zmp;
	vector<int> ct(*max_element(w.begin(), w.end())/gsz+2,0);
	repf(i,0,n){
		int q=w[i];
		if(q>=0){
			int nxs= q/gsz +1;
			int c = accumulate(ct.begin()+nxs,ct.end(),0);
			//auto it=zmp.lower_bound(q);
			//for(;it != zmp.end() && it->first<nxs*gsz;it++) c+=it->second;
			c += accumulate(zmp+q, zmp+min(MX+1,nxs*gsz),0);
			if(c<k) zmp[q]++,  ct[q/gsz]++;
		}else{
			if(zmp[-q]>0) zmp[-q]--, ct[-q/gsz]--; 
		}
	}
	
	cout << accumulate(ct.begin(),ct.end(),0) << endl;
	
	return 0;

}
0