結果
問題 | No.258 回転寿司(2) |
ユーザー |
![]() |
提出日時 | 2016-01-08 02:02:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,743 bytes |
コンパイル時間 | 1,023 ms |
コンパイル使用メモリ | 91,372 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-11-06 18:56:58 |
合計ジャッジ時間 | 4,240 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include <iostream> #include <iomanip> #include <vector> #include <list> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <cmath> #include <cstring> #include <limits> using namespace std; #define FOR(x,y) for(int x = 0;x < (y);x++) #define LLI long long int #define FORR(x,arr) for(auto& x:arr) #define ALL(a) (a.begin()),(a.end()) #define _L(x) cout<<(x)<<endl struct Element{ LLI Value; vector<int> R; }; Element dp[1001][2]; int N; vector<int> V; int main() { cin >> N; V.resize(N + 1); FOR(i,N) { cin >> V[i + 1]; } dp[0][0] = {0, vector<int>()}; dp[0][1] = {0, vector<int>()}; dp[1][0] = {0, vector<int>()}; dp[1][1].Value = V[1]; dp[1][1].R.push_back(1); for(int i = 2;i <=N;i++) { if(dp[i-1][0].Value > dp[i-1][1].Value) { dp[i][0] = dp[i-1][0]; } else { dp[i][0] = dp[i-1][1]; } if(dp[i-2][0].Value > dp[i-2][1].Value) { vector<int> newR = dp[i-2][0].R; newR.push_back(i); dp[i][1] = {V[i] + dp[i-2][0].Value, newR}; } else { vector<int> newR = dp[i-2][1].R; newR.push_back(i); dp[i][1] = {V[i] + dp[i-2][1].Value, newR}; } } if(dp[N][0].Value > dp[N][1].Value) { cout << dp[N][0].Value << endl; FORR(r, dp[N][0].R) { cout << r << " "; } cout << endl; } else { cout << dp[N][1].Value << endl; FORR(r, dp[N][1].R) { cout << r << " "; } cout << endl; } return 0; }