結果

問題 No.871 かえるのうた
ユーザー 沙耶花
提出日時 2019-08-30 21:39:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 177,376 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-30 10:45:10
合計ジャッジ時間 4,536 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000


int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<long long> X(N),A(N);
	
	for(int i=0;i<N;i++)cin>>X[i];
	for(int i=0;i<N;i++)cin>>A[i];
	
	queue<int> Q;
	Q.push(K-1);
	
	vector<bool> B(N,false);
	B[K-1]=true;
	
	while(Q.size()!=0){
		int now = Q.front();
		Q.pop();
		
		int l = lower_bound(X.begin(),X.end(),X[now]-A[now])-X.begin();
		//cout<<'l'<<l<<endl;
		for(int i=l;true;i++){
			if(i==N)break;
			if(X[now]+A[now]<X[i])break;
			if(B[i])break;
			B[i]=true;
			Q.push(i);
		}
		
		int r = upper_bound(X.begin(),X.end(),X[now]+A[now])-X.begin()-1;
		//cout<<'r'<<r<<endl;
		for(int i=r;true;i--){
			if(i<0)break;
			if(X[now]-A[now]>X[i])break;
			if(B[i])break;
			B[i]=true;
			Q.push(i);
		}
	}
	
	int ans = 0;
	for(int i=0;i<N;i++){
		if(B[i])ans++;
	}
	
	cout<<ans<<endl;
		
		
		
	
	
	return 0;
}
0