結果
問題 | No.871 かえるのうた |
ユーザー |
![]() |
提出日時 | 2019-08-30 22:09:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 235 ms / 2,000 ms |
コード長 | 1,523 bytes |
コンパイル時間 | 2,697 ms |
コンパイル使用メモリ | 213,656 KB |
最終ジャッジ日時 | 2025-01-07 15:56:06 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define P pair<ll,ll>#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)#define TO(x,t,f) ((x)?(t):(f))#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted#define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted#define REV(x) (reverse(x.begin(),x.end())) //reversell gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}#define NEXTP(x) next_permutation(x.begin(),x.end())const ll INF=ll(1e18)+ll(7);const ll MOD=1000000007LL;#define out(a) cout<<fixed<<setprecision((a))int main(){ll N,K;cin >> N >> K;K--;ll ans = 0;set<ll> setX;map<ll,ll> indexX;vector<ll> A(N),X(N);FOR(i,0,N){cin >> X[i];if(i!=K)setX.insert(X[i]);indexX[X[i]] = i;}FOR(i,0,N)cin >> A[i];queue<ll> nex;vector<bool> did(N,0);nex.push(K);did[K] = true;while(nex.size()){ans++;ll nowi = nex.front();nex.pop();ll nowX = X[nowi];ll nowA = A[nowi];vector<ll> usedX;auto it = setX.upper_bound(nowX-nowA-1LL);auto la = setX.upper_bound(nowX+nowA);while(it != la){ll XXX = *it;nex.push(indexX[XXX]);usedX.push_back(XXX);++it;}for(auto xxx:usedX){setX.erase(xxx);}}cout << ans << endl;}