結果
問題 | No.2916 累進コスト最小化 |
ユーザー |
![]() |
提出日時 | 2024-10-06 18:14:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 236 ms / 3,500 ms |
コード長 | 1,028 bytes |
コンパイル時間 | 1,325 ms |
コンパイル使用メモリ | 103,324 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-10-06 18:14:29 |
合計ジャッジ時間 | 5,256 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include<iostream>#include<vector>#include<algorithm>using namespace std;using ll = long long;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);ll n,m,c;cin>>n>>m>>c;vector<vector<pair<ll,ll>>> g(n,vector<pair<ll,ll>>(n,make_pair(-1,-1)));for(int i = 0;i<m;i++){ll u,v,r,w;cin>>u>>v>>r>>w;u--;v--;pair<ll,ll> now = make_pair(r,w);g[u][v] = g[v][u] = now;}vector<vector<ll>> dp(n,vector<ll>(c+1,-1));dp[n-1][0] = 0;for(int i = 0;i<=c;i++) dp[n-1][i] = i;for(int i = 1;i<=c;i++){for(int j = 0;j<n;j++){for(int k = 0;k<n;k++){auto now = g[j][k];if(now.first==-1) continue;ll cost = i / now.first;cost += now.second;if(cost>i) continue;ll nj = i - cost;dp[j][i] = max(dp[j][i],dp[k][nj]);}}}for(int i = 1;i<=c;i++) cout<<dp[0][i]<<endl;}