結果
問題 | No.258 回転寿司(2) |
ユーザー |
![]() |
提出日時 | 2015-08-18 22:08:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 795 bytes |
コンパイル時間 | 1,430 ms |
コンパイル使用メモリ | 164,612 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 18:52:43 |
合計ジャッジ時間 | 4,764 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include <bits/stdc++.h>using namespace std;template<typename T> string to_string(const T& v) {string str;for (const auto& i : const_cast<T&>(v)) str += to_string(i) + " ";return str.substr(0, max(0, (int)str.size() - 1));}int main() {int n;cin >> n;vector<int> v(n);for (int& i : v) cin >> i;vector<int> dp(n + 1), prv(n + 1, -1);dp[1] = v[0];for (int i = 1; i < n; ++i) {if (dp[i] > dp[i - 1] + v[i]) {dp[i + 1] = dp[i];prv[i + 1] = i;} else {dp[i + 1] = dp[i - 1] + v[i];prv[i + 1] = i - 1;}}int t = n;vector<int> res;while (t > 0) {if (prv[t] != t - 1) res.emplace_back(t);t = prv[t];}reverse(res.begin(), res.end());cout << dp.back() << endl;cout << to_string(res) << endl;}