結果
| 問題 | No.871 かえるのうた | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-05-05 15:36:33 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 51 ms / 2,000 ms | 
| コード長 | 607 bytes | 
| コンパイル時間 | 2,074 ms | 
| コンパイル使用メモリ | 193,616 KB | 
| 最終ジャッジ日時 | 2025-01-10 06:48:33 | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 49 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int n,k; scanf("%d%d",&n,&k); k--;
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         rep(i,n) scanf("%lld",&x[i]);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%lld",&ra[i]);
      |                  ~~~~~^~~~~~~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
	int n,k; scanf("%d%d",&n,&k); k--;
	vector<lint> x(n),ra(n);
	rep(i,n) scanf("%lld",&x[i]);
	rep(i,n) scanf("%lld",&ra[i]);
	lint xl=x[k]-ra[k],xr=x[k]+ra[k];
	int l=k,r=k;
	while(1){
		bool end=true;
		if(l>0 && xl<=x[l-1]){
			xl=min(xl,x[l-1]-ra[l-1]);
			xr=max(xr,x[l-1]+ra[l-1]);
			l--;
			end=false;
		}
		if(r<n-1 && x[r+1]<=xr){
			xl=min(xl,x[r+1]-ra[r+1]);
			xr=max(xr,x[r+1]+ra[r+1]);
			r++;
			end=false;
		}
		if(end) break;
	}
	printf("%d\n",r-l+1);
	return 0;
}
            
            
            
        