QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#586085 | #5145. Shortest Path | Insert_Username_Here | WA | 1ms | 7696kb | C++20 | 3.1kb | 2024-09-24 01:55:45 | 2024-09-24 01:55:46 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll mod = 998244353;
// #include <brawlstars>
// FOR PAIN OR FOR GLORYYY ELLL PRIMOOOOOO
const ll N = 2001, M = 5001;
ll dis[2][4 * N][N], dist[2][N], cnt, ans;
pii cht[2 * M];
bool comp(const pii &a, const pii &b) {
if(a.f == b.f) return a.s < b.s;
return a.f > b.f;
}
long double slope(pii a, pii b) {
return -1 * (a.s - b.s) / (a.f - b.f);
}
void bk(ll n) {
sort(cht, cht + cnt, comp);
vector<ll> stk;
for(ll i = 0; i < cnt; i++) {
if(stk.size() && cht[stk.back()].f == cht[i].f) continue;
ll j = stk.size() - 2;
while(j >= 0 && slope(cht[stk[j]], cht[stk.back()]) <= slope(cht[stk.back()], cht[i])) stk.pop_back(), j--;
stk.push_back(i);
}
ll prv = 0, nxt;
pii cur;
for(ll i = 0; i < (ll)stk.size(); i++) {
nxt = n;
if(i != (ll)stk.size() - 1) nxt = min(n, (ll)slope(cht[stk[i]], cht[stk[i + 1]]));
if(nxt <= 0) continue;
cur = cht[stk[i]], cur.f %= mod, cur.s %= mod;
ans = (ans + (prv + nxt + 1) * (nxt - prv) / 2 % mod * cur.f + (nxt - prv) * cur.s) % mod;
prv = nxt;
if(prv == n) break;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while(t--) {
ll n, m, x;
cin >> n >> m >> x;
ans = 0;
pair<pii, ll> edges[m];
for(ll i = 0; i < m; i++) cin >> edges[i].f.f >> edges[i].f.s >> edges[i].s;
for(ll i = 0; i <= 4 * n; i++) {
for(ll j = 0; j <= n; j++) dis[0][i][j] = dis[1][i][j] = 1e18;
}
dis[0][0][1] = dis[1][0][n] = 0;
for(ll i = 1; i <= 4 * n; i++) {
for(auto j : edges) {
dis[0][i][j.f.s] = min(dis[0][i][j.f.s], dis[0][i - 1][j.f.f] + j.s);
dis[0][i][j.f.f] = min(dis[0][i][j.f.f], dis[0][i - 1][j.f.s] + j.s);
dis[1][i][j.f.s] = min(dis[1][i][j.f.s], dis[1][i - 1][j.f.f] + j.s);
dis[1][i][j.f.f] = min(dis[1][i][j.f.f], dis[1][i - 1][j.f.s] + j.s);
}
}
if(dis[0][4 * n][n] == 1e18 && dis[0][4 * n - 1][n] == 1e18) {
cout << "0\n";
continue;
}
for(ll i = 1; i <= min(4 * n, x); i++) {
if(dis[0][i][n] != 1e18) ans = (ans + dis[0][i][n]) % mod;
}
if(x <= 4 * n) {
cout << ans << "\n";
continue;
}
for(ll i = 1; i <= n; i++) dist[0][i] = dist[1][i] = 1e18;
for(ll i = 0; i <= 4 * n; i++) {
for(ll j = 1; j <= n; j++) dist[0][i] = min(dist[0][i], dis[0][i][j] + dis[1][4 * n - i][j]);
if(i == 4 * n) break;
for(ll j = 1; j <= n; j++) dist[1][i] = min(dist[1][i], dis[0][i][j] + dis[1][4 * n - i - 1][j]);
}
cnt = 0;
for(ll i = 0; i < m; i++) {
if(dist[0][edges[i].f.f] != 1e18) cht[cnt] = {2 * edges[i].s, dist[0][edges[i].f.f]}, cnt++;
if(dist[0][edges[i].f.s] != 1e18) cht[cnt] = {2 * edges[i].s, dist[0][edges[i].f.s]}, cnt++;
}
bk((x - 4 * n) / 2);
cnt = 0;
for(ll i = 0; i < m; i++) {
if(dist[1][edges[i].f.f] != 1e18) cht[cnt] = {2 * edges[i].s, dist[1][edges[i].f.f]}, cnt++;
if(dist[1][edges[i].f.s] != 1e18) cht[cnt] = {2 * edges[i].s, dist[1][edges[i].f.s]}, cnt++;
}
bk((x - 4 * n + 1) / 2);
cout << ans << "\n";
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5660kb
input:
4 3 2 10 1 2 5 2 3 4 3 0 1000000000 3 3 100 1 2 3 1 3 4 2 3 5 4 6 1000000000 1 2 244 1 2 325 1 4 927 3 3 248 2 4 834 3 4 285
output:
125 0 15300 840659991
result:
ok 4 number(s): "125 0 15300 840659991"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7696kb
input:
400 4 7 850187899 1 2 83 1 2 24 3 1 23 2 3 80 3 3 65 1 2 55 2 4 31 4 7 297586795 3 4 54 1 1 66 2 2 75 1 3 68 1 4 27 1 4 29 2 3 96 5 7 217277444 3 3 9 3 4 36 2 2 77 5 5 38 3 3 6 1 2 18 1 2 23 5 6 379032278 5 5 96 4 3 92 3 2 49 4 3 44 1 4 19 1 1 18 5 6 534284598 5 1 59 1 2 2 3 3 55 2 2 24 5 4 34 2 4 7...
output:
191476186 406722183 0 0 58483482 115858544 177378789 656019644 858116309 0 38761681 633010531 0 696693112 919354187 122684249 865793975 91541737 248634956 0 374201737 455984810 284991806 322357914 0 514668426 407812429 555256220 0 419773408 989291360 743372489 0 716008724 0 189418326 244106015 41273...
result:
wrong answer 50th numbers differ - expected: '794512265', found: '355595092'