結果

問題 No.258 回転寿司(2)
ユーザー motimoti
提出日時 2015-11-17 19:01:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,748 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 104,048 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-16 01:28:10
合計ジャッジ時間 5,089 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,384 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,384 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
testcase_21 WA -
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,384 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,384 KB
testcase_48 AC 2 ms
4,384 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 2 ms
4,384 KB
testcase_54 AC 2 ms
4,508 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

using ll  = long long;
int const inf = 1<<29;

int main() {

  int N; cin >> N;

  vector<int> v(N);
  rep(i, N) {
    cin >> v[i];
  }

  if(N == 1) {
    cout << v[0] << endl << 1 << endl;
    return 0;
  }

  vector<pair<int, int>> dp(N);
  rep(i, N) {
    dp[i] = {v[i], -1};
  }
  rep(i, N) rep(j, i-1) {
    if(dp[i].first < dp[j].first + v[i]) {
      dp[i] = {dp[j].first + v[i], j};
    }
  }

  /*
  rep(i, dp.size()) {
    cout << dp[i].first << " " << dp[i].second << endl;
  }
  exit(0);
  */

  vector<int> ans;
  if(dp[N-1].first < dp[N].first) {
    cout << dp[N].first << endl;
    int curr = N;
    ans.push_back(N);
    while(dp[curr].second >= 0) {
      ans.push_back(dp[curr].second);
      curr = dp[curr].second;
    }
  }
  else {
    cout << dp[N-1].first << endl;
    int curr = N-1;
    ans.push_back(N-1);
    while(dp[curr].second >= 0) {
      ans.push_back(dp[curr].second);
      curr = dp[curr].second;
    }
  }

  rep(i, ans.size()) {
    if(i) cout << " ";
    cout << ans[(int)ans.size()-1-i] + 1;
  }
  cout << endl;

  return 0;
}
0