結果
| 問題 |
No.258 回転寿司(2)
|
| コンテスト | |
| ユーザー |
square1001
|
| 提出日時 | 2016-11-05 14:10:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 641 bytes |
| コンパイル時間 | 1,645 ms |
| コンパイル使用メモリ | 171,192 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-06 19:09:39 |
| 合計ジャッジ時間 | 4,977 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 67 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int n, a[1009], dp[1009], pre[1009];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < n; i++) {
dp[i] = a[i]; pre[i] = -1;
for(int j = i - 3; j < i - 1; j++) {
if(dp[j] + a[i] > dp[i]) {
dp[i] = dp[j] + a[i];
pre[i] = j;
}
}
}
int res = max_element(dp, dp + n) - dp;
cout << dp[res] << endl;
int pos = res; vector<int> v;
while(pos != -1) {
v.push_back(pos);
pos = pre[pos];
}
reverse(v.begin(), v.end());
for(int i = 0; i < v.size(); i++){
if(i) cout << ' ';
cout << v[i] + 1;
}
return 0;
}
square1001