結果

問題 No.45 回転寿司
ユーザー subsn
提出日時 2023-06-09 16:08:03
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 339 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 25,728 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-01 20:28:43
合計ジャッジ時間 1,456 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |     scanf("%d",&N);
      |     ^~~~~~~~~~~~~~
main.c:10:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%d%d",dp,dp+1);
      |     ^~~~~~~~~~~~~~~~~~~~~
main.c:13:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%d",&d);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
int max(int a,int b){
	return a<b?b:a;
}
int main(){
	int N,d,i;
    scanf("%d",&N);
    int* dp=malloc(N*sizeof(int));
    scanf("%d%d",dp,dp+1);
    dp[1]=max(dp[0],dp[1]);
    for(i=2;i<N;++i){
    	scanf("%d",&d);
    	dp[i]=max(dp[i-2]+d,dp[i-1]);
    }
    printf("%d\n",dp[N-1]);
    free(dp);
}
0