QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#731210 | #9569. Subway | ucup-team3282 | WA | 3ms | 18800kb | C++14 | 3.5kb | 2024-11-10 00:40:08 | 2024-11-10 00:40:10 |
Judging History
answer
/*
An unfinished naïve solution
may need Li-Chao Segment Tree
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <array>
using namespace std;
// #define Debug
// #define LOCAL
// #define TestCases
const int N = 2e5;
const int V = 4e5;
const long long Inf = 0x3f3f3f3f3f3f3f3fll;
int n, k;
long long a[N + 5], b[N + 5];
int node;
int e[V + 5][2], to[V + 5][2];//0: left, 1: right; -1: no edge
struct Node
{
int u, site, line;
long long dis;
int cur;
bool operator < (const Node& node) const
{
return dis > node.dis;
}
};
struct Site
{
typedef array<int, 2> Info;// {u, line}
vector<Info> vec;
void push(int u, int line)
{
vec.push_back(Info{u, line});
return ;
}
void init()
{
sort(vec.begin(), vec.end(), [&](Info x, Info y){ return a[x[0]] < a[y[0]]; });
return ;
}
bool check(int cur)
{
return cur + 1 < vec.size();
}
Node next(int belong, int lst, long long dis, int cur)
{
int line = vec[cur][1];
return Node{vec[cur][0], belong, line, dis + b[lst] * a[line], 0};
}
long long answer(long long dis[])
{
long long ans = Inf;
for (auto info : vec)
ans = min(ans, dis[info[0]]);
return ans;
}
};
Site site[N + 5];
priority_queue<Node> q;
long long dis[V + 5];
bool done[V + 5];
void dijkstra()
{
memset(dis, 0x3f, sizeof(dis));
for (auto info : site[1].vec)
{
int u = info[0], line = info[1];
dis[u] = 0;
q.push(Node{u, 1, line, 0ll, 0});
}
while (!q.empty())
{
auto node = q.top();
q.pop();
int u = node.u, belong = node.site, line = node.line, cur = node.cur;
if (done[u])
continue;
done[u] = 1;
#ifdef Debug
cout << "u = " << u << " site = " << belong << " line = " << line << " dis = "
<< node.dis << " cur " << cur << endl;
#endif
if (cur == 0)
{
if (to[u][0] != -1)
{
Node nxt{u - 1, to[u][0], line, node.dis + e[u][0], 0};
if (dis[u - 1] > nxt.dis)
{
dis[u - 1] = nxt.dis;
q.push(nxt);
}
}
if (to[u][1] != -1)
{
Node nxt{u + 1, to[u][1], line, node.dis + e[u][1], 0};
if (dis[u + 1] > nxt.dis)
{
dis[u + 1] = nxt.dis;
q.push(nxt);
}
}
}
if (site[belong].check(cur))
{
q.push(Node{u, belong, line, node.dis, cur + 1});
}
{
auto nxt = site[belong].next(belong, line, node.dis, cur);
if (dis[nxt.u] > nxt.dis)
{
dis[nxt.u] = nxt.dis;
q.push(nxt);
}
}
}
return ;
}
void solve()
{
cin >> n >> k;
for (int i = 1; i <= k; i++)
cin >> a[i];
for (int i = 1; i <= k; i++)
cin >> b[i];
for (int t = 1, len; t <= k; t++)
{
cin >> len;
vector<int> x(len + 1), w(len);
for (int i = 1; i < len; i++)
cin >> x[i] >> w[i];
cin >> x[len];
for (int i = 1; i <= len; i++)
{
node++;
site[x[i]].push(node, t);
to[node][0] = to[node][1] = -1;
if (i > 1)
e[node][0] = w[i - 1], to[node][0] = x[i - 1];
if (i < len)
e[node][1] = w[i], to[node][1] = x[i + 1];
}
}
for (int i = 1; i <= n; i++)
site[i].init();
dijkstra();
for (int i = 2; i <= n; i++)
cout << site[i].answer(dis) << " ";
cout << endl;
return ;
}
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("mycode.out", "w", stdout);
#endif
ios :: sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
#ifdef TestCases
cin >> T;
#endif
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18800kb
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: -100
Wrong Answer
time: 3ms
memory: 18076kb
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 132 131 138
result:
wrong answer 3rd numbers differ - expected: '43', found: '132'