結果

問題 No.258 回転寿司(2)
コンテスト
ユーザー ciel
提出日時 2015-08-02 01:45:01
言語 C++11(廃止可能性あり)
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 500 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 351 ms
コンパイル使用メモリ 59,920 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-25 16:33:12
合計ジャッジ時間 12,217 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc-15/include/c++/15.2.0/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/bits/allocator.h:46,
         次から読み込み:  /usr/local/gcc-15/include/c++/15.2.0/vector:65,
         次から読み込み:  main.cpp:1:
In member function ‘void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]’,
    inlined from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {const int&}; _Tp = int]’ at /usr/local/gcc-15/include/c++/15.2.0/bits/alloc_traits.h:674:17,
    inlined from ‘void std::vector<_Tp, _Alloc>::_M_realloc_append(_Args&& ...) [with _Args = {const int&}; _Tp = int; _Alloc = std::allocator<int>]’ at /usr/local/gcc-15/include/c++/15.2.0/bits/vector.tcc:586:26,
    inlined from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>]’ at /usr/local/gcc-15/include/c++/15.2.0/bits/stl_vector.h:1427:21,
    inlined from ‘int main()’ at main.cpp:19:43:
/usr/local/gcc-15/include/c++/15.2.0/bits/new_allocator.h:191:11: 警告: ‘idx’ may be used uninitialized [-Wmaybe-uninitialized]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:15:18: 備考: ‘idx’ はここで定義されています
   15 |         int ma=0,idx;
      |                  ^~~

ソースコード

diff #
raw source code

#include <vector>
#include <cstdio>
#define BACK 2
int main(){
	int n;
	scanf("%d",&n);
	std::vector<int>v(n),prev(n);
	for(int i=0;i<n;i++){
		scanf("%d",&v[i]);
		int ma=0,_prev=-1;
		for(int j=0;j<=i-BACK;j++)if(ma<v[j])ma=v[j],_prev=j;
		v[i]+=ma;
		prev[i]=_prev;
	}
	int ma=0,idx;
	for(int i=n-BACK;i<n;i++)if(i>=0&&ma<v[i])ma=v[i],idx=i;
	printf("%d\n",ma);
	std::vector<int>bk;
	for(int i=idx;i>=0;i=prev[i])bk.push_back(i);
	for(int i=bk.size()-1;i>=0;i--)printf(i>0?"%d ":"%d\n",bk[i]+1);
}
0