結果

問題 No.45 回転寿司
ユーザー kashi3215kashi3215
提出日時 2018-07-11 19:02:31
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 453 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 24,320 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 19:13:59
合計ジャッジ時間 1,190 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |                 scanf("%d", &a[i]);
      |                 ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
int main(void) {
	int N, i;
	scanf("%d", &N);
	int *a = (int *)calloc(N, sizeof(int));
	int *b = (int *)calloc(N, sizeof(int));
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	b[0] = a[0];
	if (a[0] > a[1]) {
		b[1] = a[0];
	}
	else { b[1] = a[1]; }
	for (i = 0; i < N-2; i++) {
		if (b[i]+a[i+2] > b[i+1]) {
			b[i+2] = b[i] + a[i+2];
		}
		else {
			b[i+2] = b[i+1];
		}
	}
	printf("%d\n", b[N-1]);
	return 0;
}
0