結果

問題 No.45 回転寿司
ユーザー arishikiarishiki
提出日時 2016-04-04 12:31:56
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 875 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-05-03 11:51:40
合計ジャッジ時間 12,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:15:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |   scanf("%d", &N);
      |   ^~~~~~~~~~~~~~~
main.c:18:20: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |   for(i=0;i<N;i++) scanf("%d", V+i);
      |                    ^~~~~~~~~~~~~~~~

ソースコード

diff #

#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));
}
0