QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875589 | #9569. Subway | Andyqian7 | WA | 47ms | 290288kb | C++26 | 2.8kb | 2025-01-29 23:39:53 | 2025-01-29 23:39:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 410000;
const ll INF = 1e18;
int n, m;
int a[N], b[N];
int t, to[N], id[N];
vector<pair<int, int>> e[N];
vector<int> v[N];
deque<int> st[N];
int stp[N];
ll dis[N];
bool vis[N];
ll ans[N];
inline ll calc(int x, int y)
{
return dis[x] + 1ll * a[id[y]] * b[id[x]];
}
inline double slope(int x, int y)
{
if (b[id[x]] == b[id[y]])
return INF * (dis[x] > dis[y]);
if (dis[x] == dis[y])
return INF * (b[id[x]] > b[id[y]]);
return -1.0 * (b[id[x]] - b[id[y]]) / (dis[x] - dis[y]);
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
scanf("%d", &b[i]);
for (int i = 1; i <= m; i++)
{
int siz;
scanf("%d", &siz);
int lst;
{
int x;
scanf("%d", &x);
t++, to[t] = x, id[t] = i;
v[x].push_back(t);
lst = t;
}
for (int j = 2; j <= siz; j++)
{
int w, x;
scanf("%d%d", &w, &x);
t++, to[t] = x, id[t] = i;
e[lst].push_back(make_pair(t, w));
v[x].push_back(t);
lst = t;
}
}
for (int i = 1; i <= n; i++)
{
sort(v[i].begin(), v[i].end(), [](const int x, const int y)
{ return a[id[x]] < a[id[y]]; });
}
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
for (int i = 1; i <= t; i++)
if (to[i] == 1)
pq.push(make_pair(0, i));
else
dis[i] = INF;
for (int i = 1; i <= n; i++)
ans[i] = INF;
while (pq.empty() == 0)
{
int x = pq.top().second;
int tmp = pq.top().first;
pq.pop();
if (vis[x])
continue;
vis[x] = 1;
int i = to[x];
dis[x] = tmp;
ans[i] = min(ans[i], dis[x]);
while (stp[i] < (int)v[i].size() && vis[v[i][stp[i]]])
stp[i]++;
if (stp[i] < (int)v[i].size())
{
int y = v[i][stp[i]];
while (st[i].size() > 1 && slope(st[i][st[i].size() - 2], st[i].back()) < slope(st[i].back(), x))
st[i].pop_back();
st[i].push_back(x);
while (st[i].size() > 1 && calc(st[i][0], y) > calc(st[i][1], y))
st[i].pop_front();
if (calc(st[i][0], y) < dis[y])
pq.push(make_pair(calc(st[i][0], y), y));
}
for (auto pr : e[x])
{
int y = pr.first, z = pr.second;
if (dis[x] + z < dis[y])
pq.push(make_pair(dis[x] + z, y));
}
}
for (int i = 2; i <= n; i++)
printf("%lld ", ans[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 44ms
memory: 290276kb
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: 47ms
memory: 290288kb
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: 45ms
memory: 290216kb
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:
-1188932732 -1616297129 -793292879 701911826
result:
wrong answer 1st numbers differ - expected: '817370554', found: '-1188932732'