結果
問題 | No.258 回転寿司(2) |
ユーザー |
![]() |
提出日時 | 2016-05-15 01:07:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,366 bytes |
コンパイル時間 | 706 ms |
コンパイル使用メモリ | 86,152 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-06 19:02:25 |
合計ジャッジ時間 | 4,117 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <list> #include <stack> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; int main(){ ios::sync_with_stdio(false); int N; cin >> N; vector<int> v; rep(i,N){ int a; cin >> a; v.push_back(a); } vector<int> dp(N,0); rep(i,N) dp[i] = v[i]; rep(i,N){ REP(j,i+2,N){ dp[j] = max(dp[j], dp[i]+v[j]); } } int now_i = N-1; int mx = -1; rep(i,N){ if(mx < dp[i]){ mx = dp[i]; now_i = i; } } vector<int> ret; int now = dp[now_i]; cout << now << endl; while(true){ bool flg = false; rep(i,now_i-1){ if(dp[i] == dp[now_i]-v[now_i]){ ret.push_back(now_i); now_i = i; now = dp[now_i]; flg = true; break; } } if(!flg){ ret.push_back(now_i); break; } } reverse(ALLOF(ret)); rep(i,ret.size()){ if(i!=0) cout << " "; cout << ret[i]+1; } cout << endl; return 0; }