結果

問題 No.45 回転寿司
ユーザー Unbakedbread
提出日時 2025-12-11 01:56:05
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 337 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 696 ms
コンパイル使用メモリ 76,832 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-11 01:56:08
合計ジャッジ時間 2,360 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%hd", &N);
      |         ~~~~~^~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%hhd", &V);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>

int8_t V;
int16_t N, dp1, dp2;

int main(void) {
	scanf("%hd", &N);
	
	for(int16_t i = 0; i < N; ++i) {
		scanf("%hhd", &V);
		if(i & 1) {
			if(dp1 > dp2) dp2 = dp1;
			dp1 += V;
		} else {
			if(dp2 > dp1) dp1 = dp2;
			dp2 += V;
		}
	}
	
	if(dp1 < dp2) printf("%d\n", dp2);
	else printf("%d\n", dp1);
	return 0;
}
0