結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
|
| 提出日時 | 2016-04-06 14:37:06 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 976 bytes |
| コンパイル時間 | 156 ms |
| コンパイル使用メモリ | 20,992 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2024-11-24 11:37:48 |
| 合計ジャッジ時間 | 164,275 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 TLE * 26 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:20:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%d", &N);
| ^~~~~~~~~~~~~~~
main.c:23:20: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | for(i=0;i<N;i++) scanf("%d", V+i);
| ^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
/* ルールの説明がわかりにくいが、
間を1個以上開けた上昇列として指定し、
和が最大になるようにする*/
/* 間は1個開けるか2個開けるかどっちか。
なぜなら、3つ以上開ける時、その真ん中にあるやつを他を変えずに取れるから。*/
/* 最初の2個のうち、どちらかはとることになる*/
/* 寿司の基本定理
-*-の方が*-*より大きい
ならば真ん中は必ず採用
*/
int mymax(int a, int b);
int maxsushi(int *V, int N);
int main(void){
int i, N;
scanf("%d", &N);
int V[N];
for(i=0;i<N;i++) scanf("%d", V+i);
printf("%d\n", maxsushi(V, N));
return 0;
}
int mymax(int a, int b){
if(a>b) return a;
else return b;
}
int maxsushi(int *V, int N){
if(N<=0) return 0;
else if(N==1)
return *V;
else if(N==2)
return mymax(*V, *(V+1));
else
return mymax((*V)+maxsushi(V+2, N-2), (*(V+1))+maxsushi(V+3, N-3));
}