結果

問題 No.1676 Coin Trade (Single)
ユーザー umezoumezo
提出日時 2021-09-10 23:41:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,340 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 212,652 KB
実行使用メモリ 12,760 KB
最終ジャッジ日時 2023-09-02 23:16:42
合計ジャッジ時間 4,664 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 51 ms
10,500 KB
testcase_04 AC 45 ms
9,740 KB
testcase_05 AC 44 ms
9,088 KB
testcase_06 AC 43 ms
9,260 KB
testcase_07 AC 36 ms
8,528 KB
testcase_08 AC 26 ms
6,444 KB
testcase_09 AC 36 ms
7,992 KB
testcase_10 AC 38 ms
8,428 KB
testcase_11 AC 50 ms
10,416 KB
testcase_12 AC 30 ms
7,408 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 61 ms
12,672 KB
testcase_34 AC 64 ms
12,760 KB
testcase_35 AC 60 ms
12,700 KB
testcase_36 AC 64 ms
12,692 KB
testcase_37 AC 62 ms
12,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll INF=1e12;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

template<class T> bool chmin(T& a,T b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,k;
  cin>>n>>k;
  
  vector<ll> A(n);
  vector<pair<int,int>> B;
  
  Graph G(n);
  rep(i,n){
    ll a;
    int m;
    cin>>a>>m;
    A[i]=a;
    rep(j,m){
      int b;
      cin>>b;
      b--;
      B.push_back({i,b});
    }
  }
  
  for(auto t:B){
    ll y=t.first,x=t.second;
    if(A[x]<A[y]){
      G[x].push_back(Edge(y,(y-x)*INF-A[y]+A[x]));
    }
  }
  rep(i,n-1) G[i].push_back(Edge(i+1,INF));
  
  vector<ll> dist(n,1000000000000000000);
  int s=0;
  dist[s]=0;

  priority_queue<pli,vector<pli>,greater<pli>> que;
  que.push({dist[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;
    
    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  
  cout<<(n-1)*INF-dist[n-1]<<endl;
  
  return 0;
}
0