結果
| 問題 | No.258 回転寿司(2) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-08-02 01:45:01 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| + 824µs | |
| コード長 | 500 bytes |
| 記録 | |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 57,856 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-20 19:05:58 |
| 合計ジャッジ時間 | 10,231 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 67 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/x86_64-pc-linux-gnu/bits/c++allocator.h:33,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/allocator.h:46,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/vector:65,
from 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 /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/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 /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/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 /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_vector.h:1427:21,
inlined from 'int main()' at main.cpp:19:43:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/new_allocator.h:191:11: warning: '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: note: 'idx' was declared here
15 | int ma=0,idx;
| ^~~
ソースコード
#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);
}