結果

問題 No.258 回転寿司(2)
ユーザー albicillaalbicilla
提出日時 2017-09-23 11:16:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,749 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 172,760 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 15:21:23
合計ジャッジ時間 9,107 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
#define int long long
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int prevv[1010];
struct Edge{
  int to;int cost;
  Edge(){};
  Edge(int to,int cost){
    this->to=to;
    this->cost=cost;
  }
};

//経路復元(ダイクストラ) prevv配列 prevv[to]=fromを更新式に追加しておく アリ本p99
vector<int> get_path(int t){
  vector<int> path;
  for(;t!=0;t=prevv[t]){
    path.push_back(t);
  }
  //このままだとt->sなので逆順にする
  reverse(path.begin(),path.end());
  return path;
}

vector<Edge> edv[1010];

int d[1010];
signed main(){
  int n;
  cin>>n;
  memset(d,0x3f,sizeof(d));
  memset(prevv,-1,sizeof(prevv));
  V vec(n);
  for(int i=1;i<=n;i++){
    cin>>vec[i];
  }

  edv[0].push_back(Edge(1,-vec[1]));
  edv[0].push_back(Edge(2,-vec[2]));
  for(int i=3;i<=n;i++){
    edv[i-2].push_back(Edge(i,-vec[i]));
  }
  for(int i=4;i<=n;i++){
    edv[i-3].push_back(Edge(i,-vec[i]));
  }

  priority_queue<int> pq;
  pq.push(0);
  d[0]=0;
  while(!pq.empty()){
    int now=pq.top();pq.pop();
    rep(i,edv[now].size()){
      int next=edv[now][i].to;
      int path=edv[now][i].cost;
      if(d[now]+path<d[next]){
        d[next]=d[now]+path;
        prevv[next]=now;
        pq.push(next);
      }
    }
  }

  cout<<-d[n]<<endl;

  V pathvec= get_path(n);
  rep(i,pathvec.size()-1){
    cout<<pathvec[i]<<" ";
  }
  cout<<pathvec[pathvec.size()-1]<<endl;

}
0