結果
問題 | No.2739 Time is money |
ユーザー |
|
提出日時 | 2025-01-22 16:56:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,454 bytes |
コンパイル時間 | 1,068 ms |
コンパイル使用メモリ | 123,120 KB |
実行使用メモリ | 29,392 KB |
最終ジャッジ日時 | 2025-01-22 16:56:19 |
合計ジャッジ時間 | 12,155 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 18 |
コンパイルメッセージ
main.cpp: In function ‘int solve()’: main.cpp:89:1: warning: no return statement in function returning non-void [-Wreturn-type] 89 | } | ^ main.cpp: In function ‘int main()’: main.cpp:97:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 97 | scanf("%d%d%d%d", &a, &b, &d, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>#include <sstream>#include <iomanip>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <vector>#include <queue>#include <unordered_set>#include <unordered_map>#include <bitset>#include <ctime>#include <assert.h>#include <deque>#include <list>#include <stack>using namespace std;#define is_mul_overflow(a, b) \((b != 0) && (a > LLONG_MAX / b || a < LLONG_MIN / b))typedef pair<long long, int> pli;typedef pair<int, long long> pil;typedef pair<long long , long long> pll;typedef pair<int, int> pii;typedef pair<double, double> pdd;typedef pair<int, pii> piii;typedef pair<int, long long > pil;typedef pair<long long, pii> plii;typedef pair<double, int> pdi;typedef long long ll;typedef unsigned long long ull;typedef pair<ull, ull> puu;typedef long double ld;const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f, MID = 333;const long double EPS = 1e-8;int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};char p[10] = "ULDR";// int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};// int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};int n, m, cnt;int w[N];vector<ll> num;ll res;ll lowbit(ll x) { return x & -x; }ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }inline double rand(double l, double r) { return (double)rand() / RAND_MAX * (r - l) + l; }inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }inline ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }inline double qmi(double a, ll b) { double res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }// inline ll C(ll a, ll b) { if (a < b) return 0; if (b > a - b) b = a - b; ll res = 1; for (ll i = 1, j = a; i <= b; i++, j--) { res = res * (j %MOD) % MOD; res = res * qmi(i, MOD - 2, MOD) % MOD; } return res; }inline ll C(ll a, ll b, int* c) { if (a < b) return 0; ll res = 1; for (ll j = a, i = 1; i < b + 1; i++, j--) res *= j; for (ll j = a, i = 1; i < b +1; i++, j--) res /= i; return res; }inline int find_(int x) { return lower_bound(num.begin(), num.end(), x) - num.begin(); }int e[N], ne[N], h[N], v[N], idx, x;ll d[N], t[N];bool st[N];inline void add(int a, int b, int c, int d) { e[idx] = b, ne[idx] = h[a], w[idx] = c, v[idx] = d, h[a] = idx++; }int solve() {d[1] = 0;priority_queue<plii, vector<plii>, greater<plii>> q;q.push({0, {0, 1}});while (q.size()) {auto it = q.top(); q.pop();int u = it.second.second;if (st[u]) continue;st[u] = 1;for (int i = h[u]; ~i; i = ne[i]) {int j = e[i];if (st[j]) continue;ll nd = d[u] + w[i], nt = t[u] + v[i];nd += nt / x, nt %= x;if (d[j] > nd || d[j] == nd && t[j] > nt) {d[j] = nd, t[j] = nt;q.push({d[j], {t[j], j}});}}}if (d[n] > 1e16) puts("-1");else printf("%lld\n", d[n] + !!t[n]);}int main() {cin >> n >> m >> x;memset(h, -1, sizeof(int) * (n + 10));memset(d, 0x3f, sizeof(ll) * (n + 10));for (int i = 1; i < m + 1; i++) {int a, b, c, d;scanf("%d%d%d%d", &a, &b, &d, &c);add(a, b, c, d), add(b, a, c, d);}solve();return 0;}