結果

問題 No.258 回転寿司(2)
ユーザー albicillaalbicilla
提出日時 2017-09-23 11:10:42
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,724 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 168,868 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 15:20:08
合計ジャッジ時間 9,632 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 AC 30 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 RE -
testcase_05 WA -
testcase_06 AC 73 ms
6,940 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 76 ms
6,940 KB
testcase_15 WA -
testcase_16 RE -
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 112 ms
6,944 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 RE -
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 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 3 ms
6,944 KB
testcase_54 AC 37 ms
6,944 KB
testcase_55 RE -
testcase_56 RE -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 RE -
testcase_65 WA -
testcase_66 RE -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
権限があれば一括ダウンロードができます

ソースコード

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()
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];
int 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