結果
問題 | No.258 回転寿司(2) |
ユーザー |
|
提出日時 | 2016-11-27 22:05:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,099 bytes |
コンパイル時間 | 1,910 ms |
コンパイル使用メモリ | 182,780 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 19:09:51 |
合計ジャッジ時間 | 5,297 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 67 |
ソースコード
#include <bits/stdc++.h>using namespace std;template< class T1, class T2 >int upmax( T1 &x, T2 v ){if( x < v ){x = v;return 1;}return 0;}signed main(){int N; cin >> N;vector< int > V( N );for( int i = 0; i < N; ++i )cin >> V[ i ];vector< vector< int > > dp( N + 1, vector< int >( 2, -0x3f3f3f3f ) );vector< vector< pair< int, int > > > pre( N + 1, vector< pair< int, int > >( 2, make_pair( -1, -1 ) ) );dp[ 0 ][ 0 ] = 0;for( int i = 0; i < N; ++i ){if( upmax( dp[ i + 1 ][ 0 ], dp[ i ][ 0 ] ) )pre[ i + 1 ][ 0 ] = make_pair( i, 0 );if( upmax( dp[ i + 1 ][ 0 ], dp[ i ][ 1 ] ) )pre[ i + 1 ][ 0 ] = make_pair( i, 1 );if( upmax( dp[ i + 1 ][ 1 ], dp[ i ][ 0 ] + V[ i ] ) )pre[ i + 1 ][ 1 ] = make_pair( i, 0 );}cout << max( dp[ N ][ 0 ], dp[ N ][ 1 ] ) << endl;stack< int > ans;for( int x = N, y = dp[ N ][ 0 ] < dp[ N ][ 1 ]; x > 0; tie( x, y ) = pre[ x ][ y ] )if( y )ans.emplace( x );for( ; not ans.empty(); ans.pop() )cout << ans.top() << " \n"[ ans.size() == 1 ];return 0;}