結果

問題 No.45 回転寿司
ユーザー guracoro_corori
提出日時 2019-07-15 01:00:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 384 bytes
コンパイル時間 1,401 ms
コンパイル使用メモリ 161,732 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 00:12:41
合計ジャッジ時間 2,316 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std; 

int main(){
  int n;
  vector<int > v;
  int a[1000]={0};
  cin>>n;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  if(n>2){
    a[0]=v[0];
    a[1]=max(v[0],v[1]);
    for(int i=2;i<n;i++){
      a[i]=max(a[i-2]+v.at(i),a[i]=a[i-1]);
    }
    cout<<a[n-1]<<endl;
  }else{
    cout<<v.at(0)<<endl;
  } 
}
0