結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-04-17 02:12:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,207 bytes |
| コンパイル時間 | 687 ms |
| コンパイル使用メモリ | 57,156 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:12:21 |
| 合計ジャッジ時間 | 1,954 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:8:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#define print(x) printf("%d\n",x)
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
int main(){
const int n = getInt();
const int c = getInt();
const int v = getInt();
vector<int> s(v);
vector<int> t(v);
vector<int> y(v);
vector<int> m(v);
REP(i,v) s[i] = getInt() - 1;
REP(i,v) t[i] = getInt() - 1;
REP(i,v) y[i] = getInt();
REP(i,v) m[i] = getInt();
vector<pair<pair<int, int>, pair<int, int> > > g(v);
REP(i,v) g[i] = make_pair(make_pair(s[i], t[i]), make_pair(y[i], m[i]));
sort(g.begin(), g.end());
const int inf = 100000000;
vector<vector<int> > dp(n, vector<int>(c + 1, inf));
dp[0][c] = 0;
REP(i,v){
const int ss = g[i].first.first;
const int tt = g[i].first.second;
const int yy = g[i].second.first;
const int mm = g[i].second.second;
REP(j,c+1) if(dp[ss][j] != inf && j - yy >= 0){
dp[tt][j - yy] = min(dp[tt][j - yy], dp[ss][j] + mm);
}
}
int ans = inf;
REP(i,c+1) ans = min(ans, dp[n - 1][i]);
ans = (ans == inf ? -1 : ans);
printf("%d\n", ans);
return 0;
}
y_mazun