結果
| 問題 |
No.1676 Coin Trade (Single)
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2021-09-10 23:41:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 77 ms / 2,000 ms |
| コード長 | 1,340 bytes |
| コンパイル時間 | 2,563 ms |
| コンパイル使用メモリ | 208,560 KB |
| 最終ジャッジ日時 | 2025-01-24 12:26:52 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#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;
}
umezo