結果
問題 |
No.258 回転寿司(2)
|
ユーザー |
![]() |
提出日時 | 2025-10-05 09:41:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 504 bytes |
コンパイル時間 | 1,487 ms |
コンパイル使用メモリ | 156,976 KB |
実行使用メモリ | 19,008 KB |
最終ジャッジ日時 | 2025-10-05 09:41:41 |
合計ジャッジ時間 | 8,113 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 66 |
ソースコード
#include <bits/stdc++.h> using namespace std; int n; int v[1010]; int cnt,ans; int j,pat[1010],k,path[1010]; void dfs(int p){ if (p>n){ if (cnt>ans){ ans=cnt; k=j; for (int i=1;i<=k;i++){ path[i]=pat[i]; } } return ; } j++; pat[j]=p; cnt+=v[p]; dfs(p+2); cnt-=v[p]; j--; dfs(p+1); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n; for (int i=1;i<=n;i++){ cin>>v[i]; } dfs(1); cout<<ans<<"\n"; for (int i=1;i<=k;i++){ cout<<path[i]<<" "; } return 0; }