結果
| 問題 |
No.258 回転寿司(2)
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2016-01-08 01:56:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,758 bytes |
| コンパイル時間 | 939 ms |
| コンパイル使用メモリ | 91,308 KB |
| 実行使用メモリ | 5,632 KB |
| 最終ジャッジ日時 | 2024-11-24 10:57:59 |
| 合計ジャッジ時間 | 4,116 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 47 |
ソースコード
#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 <=1000;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+1][0].Value > dp[N+1][1].Value)
{
cout << dp[N+1][0].Value << endl;
FORR(r, dp[N+1][0].R)
{
cout << r << " ";
}
cout << endl;
}
else
{
cout << dp[N+1][1].Value << endl;
FORR(r, dp[N+1][1].R)
{
cout << r << " ";
}
cout << endl;
}
return 0;
}
nanophoto12