結果

問題 No.1007 コイン集め
ユーザー ramia777ramia777
提出日時 2022-05-27 16:56:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,805 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 93,424 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-20 19:45:48
合計ジャッジ時間 2,472 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 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 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 40 ms
4,356 KB
testcase_13 AC 38 ms
4,356 KB
testcase_14 AC 40 ms
4,356 KB
testcase_15 WA -
testcase_16 AC 16 ms
4,356 KB
testcase_17 AC 17 ms
4,356 KB
testcase_18 AC 42 ms
4,356 KB
testcase_19 AC 42 ms
4,356 KB
testcase_20 AC 41 ms
4,356 KB
testcase_21 AC 41 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Yukicoder
//Q1007 coin collect

//二次元可変配列
//vector <vector <int>> mass;
//vector <vector <int>> memo;

//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <list>//list
#include <set> //tree
#include <map> //連想配列
#include <unordered_set> //hash
#include <unordered_map> //hash
#include <algorithm>
#include <iomanip>

using namespace std;
typedef unsigned long long LL;


#define START (0)
#define RIGHT (1)
#define UP    (2)
#define LEFT  (3)
#define DOWN  (4)


vector <vector <int>> memo;

vector<int> q;
vector<int> flag;

#define DATA_MAX (1000000)
#define FMAX(a,b)  ((a)>(b)?(a):(b))

LL a[200010];

int main()
{
	LL N,k;
	LL max = 0;
	LL coin = 0;
	LL right_limit, left_limit;

	cin >> N;
	cin >> k; //現在地


	a[0] = 0;
	for (int i = 1; i <= N; i++)
		cin >> a[i];


	// 現在地が0なら0を返して終了
	if (a[k] == 0)
	{
		cout << 0 << endl;
		return 0; //end
	}
	else
	{
		LL total1 = a[k];
		LL total2 = a[k];

		//現在地よりも前方向の合計
		for(int i = k+1;i<=N;i++)
		{
			//1のところまで足していく
			if (a[i] == 1)
			{
				total1 += a[i];
				break;
			}
			total1 += a[i];
		}

		//現在地よりも後ろ方向の合計
		for (int i = k-1; i > 0; i--)
		{
			//1のところまで足していく
			if (a[i] == 1)
			{
				total2 += a[i];
				break;
			}
			total2 += a[i];
		}
		

		if (a[k] == 1)
		{
			//現在地が1なら前後どちらかしか行けないので大きいほうをコインの数とする
			coin = FMAX(total1, total2);
		}
		else
		{
			//現在値が2以上なら前後どちらも行けるので両方の合計を足す。自分自身を2重に加えているので引いておく
			coin = total1+total2 - a[k];
		}

		cout << coin << endl;
		
		//getchar();
		return 0; //end
	}
}

0