結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2019-01-17 04:10:13 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 559 bytes |
コンパイル時間 | 1,236 ms |
コンパイル使用メモリ | 29,440 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-27 19:53:22 |
合計ジャッジ時間 | 2,053 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <stdio.h> #include <stdlib.h> int main(void) { short n,i,*score; char *v; int ans; scanf("%hd",&n); v = (char *)malloc(sizeof(char) * n); if (v == NULL) { perror("v malloc"); exit(1); } for (i=0;i<n;i++) scanf("%hhd",&v[i]); score = (short *)malloc(sizeof(short) * n); score[0] = v[0]; if (n > 1) score[1] = (score[0] > v[1])? score[0]:v[1]; for (i=2;i<n;i++) { if (score[i-1] > score[i-2]+v[i]) { score[i] = score[i-1]; } else { score[i] = score[i-2]+v[i]; } } ans = score[n-1]; printf("%d\n",ans); return 0; }