結果

問題 No.871 かえるのうた
ユーザー ateate
提出日時 2019-11-20 22:35:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,604 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 203,436 KB
実行使用メモリ 415,020 KB
最終ジャッジ日時 2024-04-16 19:26:38
合計ジャッジ時間 7,839 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 16 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 124 ms
6,528 KB
testcase_15 AC 126 ms
6,400 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}

void solve1(){

  ll n,k;
  cin>>n>>k;
  k--;
  vector<ll> x(n),a(n);
  cin>>x>>a;

  vector<ll> left(n),right(n);
  rep(i,n){
    left[i]=x[i]+a[i];
    right[i]=x[i]-a[i];
  }

  vector<bool> seen(n,false);
  queue<ll> que;
  que.emplace(k);
  while(!que.empty()){
    ll i=que.front();
    que.pop();
    if(seen[i])continue;
    seen[i]=true;
    for(ll j=i+1;j<n&&x[j]<=left[i];++j){
      if(seen[j])continue;
      que.emplace(j);
    }
    for(ll j=i-1;j>=0&&x[j]>=right[i];--j){
      if(seen[j])continue;
      que.emplace(j);
    }
  }

  ll ans = 0;
  rep(i,n)ans+=seen[i];
  cout<<(ans)<<endl;

}
0