結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
Airy_Physics
|
| 提出日時 | 2020-03-27 18:21:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,457 bytes |
| コンパイル時間 | 1,034 ms |
| コンパイル使用メモリ | 99,564 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:46:04 |
| 合計ジャッジ時間 | 2,347 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>
using ll = long long int;
using namespace std;
ll INFTY = 1e10;
int main(){
// read problem
ll N, C, V, tmp;
vector<ll> S, T, Y, M;
cin >> N >> C >> V;
for(ll i = 0; i < V; i++){
cin >> tmp;
S.push_back(tmp-1);
}
for(ll i = 0; i < V; i++){
cin >> tmp;
T.push_back(tmp-1);
}
for(ll i = 0; i < V; i++){
cin >> tmp;
Y.push_back(tmp);
}
for(ll i = 0; i < V; i++){
cin >> tmp;
M.push_back(tmp);
}
// solve problem
vector<vector<ll> > dp(N, vector<ll>(C+1));
for(ll i = 0; i < N; i++){
for(ll j = 0; j < C+1; j++){
dp[i][j] = INFTY;
}
}
for(ll j = 0; j < C+1; j++){
dp[0][j] = 0;
}
ll update = 1;
//cerr << "hoge" << endl;
while(update == 1){
// reset update
update = 0;
// udpate dp
for(ll i = 0; i < V; i++){
for(ll j = 0; j <= C - Y[i]; j++){
if(dp[T[i]][j+Y[i]] > dp[S[i]][j] + M[i]){
//std::cerr << i << "," << j << endl;
update = 1;
dp[T[i]][j+Y[i]] = dp[S[i]][j] + M[i];
}
}
}
//cerr << "hoge" << endl;
}
cerr << "Answer:" << endl;
if(dp[N-1][C] < INFTY){
cout << dp[N-1][C] << endl;
}
else{
cout << -1 << endl;
}
return 0;
}
Airy_Physics