結果

問題 No.871 かえるのうた
ユーザー kotatsugamekotatsugame
提出日時 2019-09-01 05:18:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 66,804 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-08-20 09:27:33
合計ジャッジ時間 5,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 107 ms
4,836 KB
testcase_15 AC 108 ms
4,896 KB
testcase_16 AC 117 ms
4,960 KB
testcase_17 AC 96 ms
4,832 KB
testcase_18 AC 17 ms
4,380 KB
testcase_19 AC 109 ms
4,944 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 41 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 9 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 34 ms
4,380 KB
testcase_30 AC 61 ms
4,504 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 50 ms
4,392 KB
testcase_33 AC 80 ms
4,896 KB
testcase_34 AC 19 ms
4,376 KB
testcase_35 AC 50 ms
4,380 KB
testcase_36 AC 68 ms
4,672 KB
testcase_37 AC 43 ms
4,376 KB
testcase_38 AC 95 ms
4,804 KB
testcase_39 AC 89 ms
4,748 KB
testcase_40 AC 28 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 29 ms
4,644 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,K;
long X[1<<17],A[1<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>X[i];
	for(int i=0;i<N;i++)cin>>A[i];
	long L=X[--K]-A[K],R=X[K]+A[K];
	int cnt=1;
	int l=K-1,r=K+1;
	while(l>=0||r<N)
	{
		long ll=l>=0?X[K]-X[l]:(long)9e18;
		long rr=r<N?X[r]-X[K]:(long)9e18;
		if(ll<rr)
		{
			if(L<=X[l])
			{
				cnt++;
				L=min(L,X[l]-A[l]);
				R=max(R,X[l]+A[l]);
				l--;
			}
			else
			{
				if(rr<(long)9e18&&X[r]<=R)
				{
					cnt++;
					L=min(L,X[r]-A[r]);
					R=max(R,X[r]+A[r]);
					r++;
				}
				else
				{
					break;
				}
			}
		}
		else
		{
			if(R>=X[r])
			{
				cnt++;
				L=min(L,X[r]-A[r]);
				R=max(R,X[r]+A[r]);
				r++;
			}
			else
			{
				if(ll<(long)9e18&&L<=X[l])
				{
					cnt++;
					L=min(L,X[l]-A[l]);
					R=max(R,X[l]+A[l]);
					l--;
				}
				else
				{
					break;
				}
			}
		}
	}
	cout<<cnt<<endl;
}
0