結果
| 問題 |
No.258 回転寿司(2)
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-10-05 16:02:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 617 bytes |
| コンパイル時間 | 1,100 ms |
| コンパイル使用メモリ | 157,672 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-05 16:02:56 |
| 合計ジャッジ時間 | 4,128 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 67 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n, a[N], f[N][2], ans[N], cnt;
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= n; i ++ ) f[i][0] = max(f[i - 1][0], f[i - 1][1]), f[i][1] = f[i - 1][0] + a[i];
cout << max(f[n][0], f[n][1]) << endl;
int x = 0, y = 0;
if (f[n][0] > f[n][1]) x = n, y = 0;
else x = n, y = 1;
while (x)
{
if (y == 0)
{
if (f[x - 1][0] > f[x - 1][1]) x -- , y = 0;
else x -- , y = 1;
}
else ans[ ++ cnt] = x, x -- , y = 0;
}
for (int i = cnt; i >= 1; i -- ) cout << ans[i] << " ";
return 0;
}
vjudge1