結果

問題 No.871 かえるのうた
ユーザー lunnearlunnear
提出日時 2019-11-01 22:09:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,015 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 814,556 KB
最終ジャッジ日時 2023-10-13 01:00:37
合計ジャッジ時間 5,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,352 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 15 ms
4,348 KB
testcase_13 AC 5 ms
4,352 KB
testcase_14 AC 112 ms
5,732 KB
testcase_15 AC 112 ms
5,684 KB
testcase_16 MLE -
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 <iostream>
#include <list>
#include <cmath>

using namespace std;

typedef long long s8;

struct Frog
{
	s8 pos;
	s8 vol;
	bool check = false;
};

list<s8> getResList(Frog *f, s8 *n, s8 *k)
{
	list<s8> res;
	for(int i = *k - 1; i >= 0; i--)
	{
		if(abs(f[i].pos - f[(*k)].pos) <= f[(*k)].vol)
			res.push_back(i);
		else
			break;
	}
	for(int i = *k + 1; i < *n; i++)
	{
		if(abs(f[i].pos - f[(*k)].pos) <= f[(*k)].vol)
			res.push_back(i);
		else
			break;
	}
	
	return res;
}

int solve(Frog *f, s8 *n, s8 *k)
{
	int ans = 0;
	list<s8> res = getResList(f, n, k);
	for(auto i = res.begin(); i != res.end(); i++)
	{
		if(f[(*i)].check)
			continue;
		
		f[(*i)].check = true;
		ans++;
		ans += solve(f, n, &(*i));
	}
	
	return ans;
}

int main()
{
	s8 n, k;
	cin >> n >> k;
	k--;
	
	Frog frog[n];
	
	for(int i = 0; i < n; i++)
	{
		cin >> frog[i].pos;
	}
	for(int i = 0; i < n; i++)
	{
		cin >> frog[i].vol;
	}
	
	int ans = 1;
	frog[k].check = true;
	ans += solve(frog, &n, &k);
	
	cout << ans << endl;
}

0