QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#736771 | #9569. Subway | ucup-team3802 | WA | 0ms | 3660kb | C++23 | 3.9kb | 2024-11-12 13:19:06 | 2024-11-12 13:19:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for(ll i = a; i < b; i++)
const ll INF = 1'000'000'000'000'000'000;
using pl = pair<ll,ll>;
void solve(){
int n,k;
cin >> n >> k;
vector<ll> a(k),b(k);
rep(i,0,k) cin >> a[i];
rep(i,0,k) cin >> b[i];
vector<vector<array<ll,2>>> f(n);
vector<int> index(n,0);
vector<vector<array<ll,2>>> g;
vector<pl> place;
rep(i, 0, k){
ll p;
cin >> p;
ll nw;
cin >> nw;nw--;
ll ind = g.size();
f[nw].push_back({a[i], ind});
g.push_back({});
place.push_back({nw, b[i]});
rep(j, 0, p - 1) {
ll k;
cin >> k >> nw;nw--;
ll nind = g.size();
f[nw].push_back({a[i], nind});
g[ind].push_back({k, nind});
g.push_back({});
place.push_back({nw, b[i]});
ind = nind;
}
}
rep(i,0,n) sort(all(f[i]));
vector<ll> dist(g.size(), INF);
priority_queue<pl, vector<pl>, greater<pl>> q;
for(auto [cost, ind]: f[0]){
dist[ind] = 0;
q.push({0, ind});
}
priority_queue<pl, vector<pl>, greater<pl>> iq;
rep(i,0,n){
iq.push({INF, i});
}
vector<deque<pl>> lio(n);
auto check = [&](int i, int x) -> ll {
while(lio[i].size() > 1){
auto [y0, dx0] = lio[i].front();
lio[i].pop_back();
auto [y1, dx1] = lio[i].front();
if(y0 + dx0 * x < y1 + dx1 * x){
lio[i].push_front({y0, dx0});
break;
}
}
if(lio[i].size() == 0) return INF;
return lio[i].front().first + lio[i].front().second * x;
};
auto push = [&](int i, int y, int dx) -> void {
if(lio[i].size() == 0){
lio[i].push_back({y, dx});
ll nwcst = check(i, f[i][index[i]][0]);
iq.push({nwcst, i});
return;
}
if(lio[i].back().second <= dx) return;
if(index[i] == f[i].size()) return;
ll res = check(i, f[i][index[i]][0]);
while(lio[i].size() >= 2){
ll m = lio[i].size();
auto[y2, dx2] = lio[i][m-2];
auto[y1, dx1] = lio[i][m-1];
ll xx = (y2 - y) / (dx - dx2);
if(y2 + dx2 * xx > y1 + dx1 * xx) break;
lio[i].pop_back();
}
lio[i].push_back({y, dx});
ll nwcst = check(i, f[i][index[i]][0]);
if(nwcst != res){
iq.push({nwcst, i});
}
};
while(iq.size() || q.size()){
if (q.size() == 0 || (iq.size() && iq.top().first < q.top().first)){
auto[_c, ind] = iq.top();
iq.pop();
auto [ai, to] = f[ind][index[ind]];
ll cost = check(ind, ai);
if(cost != _c) continue;
if(dist[to] > cost){
dist[to] = cost;
q.push({cost, to});
}
index[ind]++;
if(index[ind] != f[ind].size()){
iq.push({check(ind, f[ind][index[ind]][0]), ind});
}
}else{
auto[cost, ind] = q.top();q.pop();
if(cost != dist[ind]) continue;
push(place[ind].first, dist[ind], place[ind].second);
for(auto [cost, to]: g[ind]){
if(dist[ind] + cost < dist[to]){
dist[to] = dist[ind] + cost;
q.push({dist[to], to});
}
}
}
}
rep(i,1,n){
ll mn = INF;
for(auto [cost, ind]: f[i]){
mn = min(mn, dist[ind]);
}
cout << mn << " ";
}cout << endl;
}
int main(){
int t = 1;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: 3624kb
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: 3488kb
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 162075978395 701911826
result:
wrong answer 3rd numbers differ - expected: '80811085745', found: '162075978395'