Contest Duration: ~ (local time) (300 minutes) Back to Home

Submission #10360538

Source Code Expand

Copy
```#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
do {                                                                         \
sort(ALL((vec)));                                                          \
(vec).erase(std::unique(ALL((vec))), (vec).end());                         \
} while (0)

ll POW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = POW(n, m / 2);
return (tmp * tmp);
} else {
return (n * POW(n, m - 1));
}
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, M, K;
cin >> N >> M >> K;
vl t(N, 0);
FOR(i, 1, N - 1) cin >> t[i];
vector<vector<tuple<ll, ll, ll>>> G(N);
vl DP(N, K + 1);
REP(i, M) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
G[a - 1].push_back(make_tuple(b - 1, c + t[b - 1], d));
G[b - 1].push_back(make_tuple(a - 1, c + t[a - 1], d));
}
DP[0] = 0;
PQ(pll) Q;
Q.push(make_pair(0, 0));
while (!Q.empty()) {
auto q = Q.top();
Q.pop();
AUTO(g, G[q.second]) {
ll next = (((q.first - 1) / get<2>(g)) + 1) * get<2>(g);
if (q.first == 0)
next = 0;
next += get<1>(g);
if (DP[get<0>(g)] > next) {
DP[get<0>(g)] = next;
Q.push(make_pair(next, get<0>(g)));
}
}
}
if (DP[N - 1] == K + 1)
cout << -1 << endl;
else
cout << DP[N - 1] << endl;
return 0;
}
```

#### Submission Info

Submission Time 2020-02-26 21:46:31+0900 H - don't be late grayf C++14 (GCC 5.4.1) 400 3565 Byte AC 197 ms 22268 KB

#### Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_1.txt, sample_2.txt, sample_3.txt
Subtask1 400 / 400 sample_1.txt, sample_2.txt, sample_3.txt, case_01.txt, case_02.txt, case_03.txt, case_04.txt, case_05.txt, case_06.txt, case_07.txt, case_08.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_14.txt, case_15.txt, case_16.txt, case_17.txt, case_18.txt, case_19.txt, case_20.txt, case_21.txt, case_22.txt, case_23.txt, case_24.txt, case_25.txt, case_26.txt
Case Name Status Exec Time Memory
case_01.txt 39 ms 5760 KB
case_02.txt 20 ms 4224 KB
case_03.txt 57 ms 7936 KB
case_04.txt 49 ms 7936 KB
case_05.txt 21 ms 3712 KB
case_06.txt 39 ms 6400 KB
case_07.txt 6 ms 1408 KB
case_08.txt 7 ms 1152 KB
case_09.txt 64 ms 8828 KB
case_10.txt 65 ms 8704 KB
case_11.txt 13 ms 2048 KB
case_12.txt 49 ms 7936 KB
case_13.txt 10 ms 3456 KB
case_14.txt 9 ms 2432 KB
case_15.txt 89 ms 11392 KB
case_16.txt 67 ms 9084 KB
case_17.txt 63 ms 10368 KB
case_18.txt 80 ms 10752 KB
case_19.txt 81 ms 10752 KB
case_20.txt 79 ms 10624 KB
case_21.txt 197 ms 22268 KB
case_22.txt 149 ms 18940 KB
case_23.txt 171 ms 20476 KB
case_24.txt 138 ms 17276 KB
case_25.txt 142 ms 21632 KB
case_26.txt 153 ms 21632 KB
sample_1.txt 1 ms 256 KB
sample_2.txt 1 ms 256 KB
sample_3.txt 1 ms 256 KB