QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419198 | #8038. Hammer to Fall | _mjj# | WA | 2ms | 4160kb | C++20 | 1.9kb | 2024-05-23 18:43:56 | 2024-05-23 18:44:11 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin() , v.end()
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int long long
using namespace std;
typedef long long LL;
typedef pair<int , int> PII;
const int N = 1e5 + 5;
const int mod = 998244353;
const int INF = 1e18;
vector<PII>g[N];
void solve()
{
int n,m,q;
cin>>n>>m>>q;
vector<int>nb(q+1,0),a(n+1,0),cnt(n+1,0);
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++)
{
int u,v,w;
cin>>u>>v>>w;
g[u].push_back({w,v});
g[v].push_back({w,u});
}
for(int i=1;i<=q;i++) cin>>nb[i];
for(int i=1;i<=n;i++) sort(all(g[i]));
vector<int>b(1,0);
for(int i=1;i<=q;i++)
{
b.push_back(nb[i]);
int j=i;
while(j+1<=q&&nb[j]==nb[j+1])j++;
i=j;
}
q = b.size()-1;
__int128 res=0;
vector<PII>query(q+1,{0,0});
for(int i=q;i>=1;i--)
{
int u = b[i];
int w = g[b[i]][0].x,v = g[b[i]][0].y;
int minv = INF,vt=-1,wt=-1;
for(auto it : g[u])
{
int w = it.x,v = it.y;
if(cnt[v]+w<minv)
{
minv = cnt[v]+w;
vt=v;
wt=w;
}
}
cnt[u]=cnt[v]+w;
query[i]={vt,wt};
}
// __int128 res=0;
// for(int i=1;i<=n;i++) res+=(__int128)cnt[i]*a[i];
for(int i=1;i<=q;i++)
{
int u = b[i],v = query[i].x,w= query[i].y;
res+=a[u]*w;
a[v]+=a[u],a[u]=0;
//cout<<u<<" "<<v<<" "<<w<<"\n";
}
int ans = res%mod;
cout<<ans<<"\n";
}
signed main(){
ios;
int T = 1;
//cin >> T;
while(T --){
solve();
}
return 0;
}
/*
2
SPR
SPSRRP
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
3 2 2 1 1 1 2 3 10 1 2 1 3 2
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
2 1 10 5000 5000 1 2 10000 1 2 2 1 2 2 1 1 1 2
output:
550000000
result:
ok single line: '550000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
10 10 10 5 14 99 14 18 4 58 39 48 60 2 4 4 6 9 56 10 8 34 7 5 96 1 3 26 3 7 92 6 8 4 5 1 72 7 6 39 7 2 93 8 8 9 10 2 2 5 9 2 3
output:
8810
result:
ok single line: '8810'
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 4160kb
input:
100 500 10000 89 61 65 85 89 2 32 97 13 70 29 86 68 74 84 64 54 39 26 84 56 95 73 11 70 26 60 40 84 58 68 33 65 71 55 2 11 71 49 85 14 59 38 11 60 8 81 78 27 32 52 49 35 94 62 72 64 50 12 45 77 74 92 67 92 38 81 39 12 29 60 70 53 33 25 60 7 83 4 85 47 32 13 58 85 86 44 68 44 1 81 62 97 7 66 62 5 16 ...
output:
671385
result:
wrong answer 1st lines differ - expected: '609241', found: '671385'