結果
問題 |
No.258 回転寿司(2)
|
ユーザー |
![]() |
提出日時 | 2016-10-18 17:41:17 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,099 bytes |
コンパイル時間 | 1,414 ms |
コンパイル使用メモリ | 161,768 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 19:08:51 |
合計ジャッジ時間 | 4,871 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define all(v) v.begin(),v.end() template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; } class Solver { public: bool solve() { int N; cin >> N; vector<int> V(N); cin >> V; vector<int> dp(N + 1); // i(1-based)を最後にとった時の美味しさの最大値 dp[0] = 0; rep(i, N) { if(i > 0) dp[i + 1] = max(dp[i], dp[i - 1] + V[i]); else dp[i + 1] = V[i]; } vector<int> takes; for(int i = N; i > 0; i--) { if(dp[i] == dp[i - 1]); else { takes.push_back(i); i--; } } reverse(all(takes)); cout << dp[N] << endl; for(auto i : takes) cout << i << (i == takes.back() ? "\n" : " "); return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Solver s; s.solve(); return 0; }