結果
問題 | No.258 回転寿司(2) |
ユーザー |
![]() |
提出日時 | 2015-09-23 07:00:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,241 bytes |
コンパイル時間 | 755 ms |
コンパイル使用メモリ | 82,276 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-06 18:53:53 |
合計ジャッジ時間 | 4,096 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include <iostream> #include <cmath> #include <climits> #include <string> #include <vector> #include <queue> #include <stack> #include <functional> #include <algorithm> #include <sstream> #include <map> #include <set> #include <utility> #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define DEBUG(x) cout<<#x<<": "<<x<<endl using namespace std; typedef pair<int,int> P; typedef long long int LL; int v[1000]; int dp[1000]; int memo[1000]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; fill(memo,memo+n,-1); REP(i,n) cin>>v[i]; dp[0]=v[0]; memo[0]=0; dp[0]=v[0]; memo[0]=0; dp[1]=v[1]; memo[1]=1; dp[2]=dp[0]+v[2]; memo[2]=0; FOR(i,3,n){ if(dp[i-2]<dp[i-3]){ memo[i]=i-3; dp[i]=dp[i-3]+v[i]; }else{ memo[i]=i-2; dp[i]=dp[i-2]+v[i]; } } int p; if(dp[n-1]>dp[n-2]){ p=n-1; }else{ p=n-2; } cout<<dp[p]<<endl; vector<int> ans; ans.push_back(p+1); while(p>1){ p=memo[p]; ans.push_back(p+1); } RREP(i,SZ(ans)){ cout<<ans[i]<<((i==0)?endl:' '); } return 0; }