結果

問題 No.258 回転寿司(2)
ユーザー albicillaalbicilla
提出日時 2017-09-23 11:51:41
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,958 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 169,612 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 15:23:19
合計ジャッジ時間 11,376 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 194 ms
6,812 KB
testcase_01 RE -
testcase_02 AC 60 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 30 ms
6,940 KB
testcase_05 RE -
testcase_06 AC 264 ms
6,944 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 14 ms
6,944 KB
testcase_13 RE -
testcase_14 AC 122 ms
6,944 KB
testcase_15 RE -
testcase_16 AC 5 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 RE -
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 61 ms
6,940 KB
testcase_21 AC 377 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 RE -
testcase_25 AC 2 ms
6,940 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 6 ms
6,940 KB
testcase_33 AC 77 ms
6,940 KB
testcase_34 AC 28 ms
6,944 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 2 ms
6,940 KB
testcase_38 RE -
testcase_39 AC 5 ms
6,940 KB
testcase_40 RE -
testcase_41 AC 281 ms
6,940 KB
testcase_42 RE -
testcase_43 AC 3 ms
6,944 KB
testcase_44 RE -
testcase_45 AC 48 ms
6,944 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 80 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 RE -
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 28 ms
6,940 KB
testcase_52 RE -
testcase_53 AC 2 ms
6,940 KB
testcase_54 AC 88 ms
6,944 KB
testcase_55 AC 273 ms
6,944 KB
testcase_56 AC 33 ms
6,940 KB
testcase_57 RE -
testcase_58 RE -
testcase_59 AC 108 ms
6,944 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 51 ms
6,940 KB
testcase_62 AC 8 ms
6,944 KB
testcase_63 RE -
testcase_64 AC 720 ms
6,940 KB
testcase_65 RE -
testcase_66 AC 2 ms
6,940 KB
testcase_67 AC 97 ms
6,940 KB
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);
      }
    }
  }


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

}
0