QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730676 | #9569. Subway | ucup-team987 | WA | 0ms | 3852kb | C++23 | 4.2kb | 2024-11-09 21:00:21 | 2024-11-09 21:00:21 |
Judging History
answer
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
void Solve() {
int n, K;
IN(n, K);
vector<int64_t> a(K), b(K);
IN(a, b);
vector<vector<int>> x(K);
vector<vector<int64_t>> w(K);
for (int k : Rep(0, K)) {
int P;
IN(P);
--P;
x[k].resize(P + 1);
w[k].resize(P);
for (int p : Rep1(0, P)) {
IN(x[k][p]);
--x[k][p];
if (p < P) {
IN(w[k][p]);
}
}
}
vector<vector<int64_t>> d(K);
for (int k : Rep(0, K)) {
d[k].assign(Sz(x[k]), INF64);
}
auto d2 = d;
priority_queue q(greater{}, vector<tuple<int64_t, int, int, int>>{});
for (int k : Rep(0, K)) {
for (int p : Rep(0, Sz(x[k]))) {
if (x[k][p] == 0) {
q.emplace(d[k][p] = 0, k, p, -1);
}
}
}
vector<vector<pair<int, int>>> lst(n);
for (int k : Rep(0, K)) {
for (int p : Rep(0, Sz(x[k]))) {
lst[x[k][p]].emplace_back(k, p);
}
}
for (int i : Rep(0, n)) {
ranges::sort(lst[i], {}, LAMBDA(x, a[x.first]));
}
vector<int> lst_ptr(n);
vector<vector<pair<int64_t, int64_t>>> lines(n);
vector<int> lines_ptr(n);
auto Eval = [&](int i) -> int64_t {
if (lst_ptr[i] == Sz(lst[i])) {
return INF64;
}
auto [k, p] = lst[i][lst_ptr[i]];
auto Go = [&](int ptr) -> int64_t {
auto [slope, intercept] = lines[i][ptr];
return slope * a[k] + intercept;
};
while (lines_ptr[i] + 1 < Sz(lines[i]) && Go(lines_ptr[i] + 1) < Go(lines_ptr[i])) {
++lines_ptr[i];
}
if (lines_ptr[i] == Sz(lines[i])) {
return INF64;
}
return Go(lines_ptr[i]);
};
while (Sz(q)) {
auto [dkp, k, p, t] = q.top();
q.pop();
if (dkp != d[k][p]) {
continue;
}
if (p + 1 < Sz(x[k])) {
if (SetMin(d[k][p + 1], dkp + w[k][p])) {
q.emplace(d[k][p + 1], k, p + 1, -1);
}
}
if (t != -1) {
if (++lst_ptr[t] < Sz(lst[t])) {
if (Eval(t) < INF64) {
auto [nk, np] = lst[t][lst_ptr[t]];
if (SetMin(d[nk][np], Eval(t)) || SetMin(d2[nk][np], Eval(t))) {
q.emplace(d[nk][np], nk, np, t);
}
}
}
}
int i = x[k][p];
if (lines[i].empty() || lines[i].back().first > b[k]) {
lines[i].emplace_back(b[k], dkp);
if (Eval(i) < INF64) {
auto [nk, np] = lst[i][lst_ptr[i]];
if (SetMin(d[nk][np], Eval(i)) || SetMin(d2[nk][np], Eval(i))) {
q.emplace(d[nk][np], nk, np, i);
}
}
}
}
vector<int64_t> ans(n, INF64);
for (int k : Rep(0, K)) {
for (int p : Rep(0, Sz(x[k]))) {
SetMin(ans[x[k][p]], d[k][p]);
}
}
OUT(ans | views::drop(1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
template <class T> concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;
namespace std {
istream& operator>>(istream& is, Range auto&& r) {
for (auto&& e : r) is >> e;
return is;
}
istream& operator>>(istream& is, Tuple auto&& t) {
apply([&](auto&... xs) { (is >> ... >> xs); }, t);
return is;
}
ostream& operator<<(ostream& os, Range auto&& r) {
auto sep = "";
for (auto&& e : r) os << exchange(sep, " ") << e;
return os;
}
ostream& operator<<(ostream& os, Tuple auto&& t) {
auto sep = "";
apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
return os;
}
} // namespace std
using namespace std;
#define LAMBDA(x, ...) ([&](auto&& x) -> decltype(auto) { return __VA_ARGS__; })
#define LAMBDA2(x, y, ...) ([&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; })
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define Rep1(...) [](int l, int r) { return Rep(l, r + 1); }(__VA_ARGS__)
#define Sz(r) int(size(r))
#define SetMin(...) LAMBDA2(x, y, y < x && (x = y, 1))(__VA_ARGS__)
#define INF64 (INT64_MAX / 2)
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')
#endif // __INCLUDE_LEVEL__ == 1
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3852kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 4611686018427387903 701911826
result:
wrong answer 3rd numbers differ - expected: '80811085745', found: '4611686018427387903'