結果

問題 No.45 回転寿司
ユーザー kashi3215
提出日時 2018-07-11 19:05:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 375 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 24,320 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 19:15:46
合計ジャッジ時間 1,191 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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:8:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |                 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));
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	if (a[0] > a[1]) {
		a[1] = a[0];
	}
	for (i = 0; i < N-2; i++) {
		if (a[i]+a[i+2] > a[i+1]) {
			a[i+2] = a[i] + a[i+2];
		}
		else {
			a[i+2] = a[i+1];
		}
	}
	printf("%d\n", a[N-1]);
	return 0;
}
0