結果
問題 | No.258 回転寿司(2) |
ユーザー |
|
提出日時 | 2018-11-02 09:13:39 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 750 bytes |
コンパイル時間 | 1,660 ms |
コンパイル使用メモリ | 163,848 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 19:24:06 |
合計ジャッジ時間 | 5,061 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; int main(){ int n,i,j; cin>>n; int v[n+2]; for(i=1;i<=n;i++) cin>>v[i]; v[n+1]=0; P dp[n+2]; dp[0]=P(0,-10); dp[1]=P(v[1],-5); for(i=2;i<=n+1;i++){ if(dp[i-2].first+v[i]>dp[i-1].first){ dp[i]=P(dp[i-2].first+v[i],i-2); } else dp[i]=P(dp[i-1].first,i-1); } vector<int> ve; int temp=n+1; cout<<dp[n].first<<endl; while(dp[temp].second>0){ temp=dp[temp].second; if(temp-1!=dp[temp].second) ve.push_back(temp); } reverse(ve.begin(),ve.end()); cout<<ve[0]; for(i=1;i<ve.size();i++) cout<<" "<<ve[i]; cout<<endl; return 0; }