結果

問題 No.1007 コイン集め
コンテスト
ユーザー forest3
提出日時 2020-07-10 11:42:51
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 563 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,576 ms
コンパイル使用メモリ 181,744 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-26 07:08:29
合計ジャッジ時間 5,088 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other AC * 5 WA * 2 RE * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:27:28: warning: ignoring return value of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = long long int]', declared with attribute 'nodiscard' [-Wunused-result]
   27 |         if( A[K] == 1 ) max( ans1 + A[K], ans2 + A[K] );
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:258:5: note: declared here
  258 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N, K;
	cin >> N >> K;
	vector<long long> A( K );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	K--;
	long long ans1 = 0;
	for( int i = K + 1; i < N; i++ ) {
		if( A[i] < 1 ) break;
		ans1 += A[i];
		if( A[i] < 2 ) break;
	}
	long long ans2 = 0;
	for( int i = K - 1; i >= 0; i-- ) {
		if( A[i] < 1 ) break;
		ans2 += A[i];
		if( A[i] < 2 ) break;
	}
	long long ans = 0;
	if( A[K] == 1 ) max( ans1 + A[K], ans2 + A[K] );
	else if( A[K] > 1 ) ans = ans1 + ans2 + A[K];

	cout << ans << endl;
}
0