QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#419205#8038. Hammer to Fall_mjj#WA 2ms3852kbC++201.8kb2024-05-23 18:49:312024-05-23 18:49:33

Judging History

你现在查看的是最新测评结果

  • [2024-05-23 18:49:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3852kb
  • [2024-05-23 18:49:31]
  • 提交

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;
    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];
    int ans=0;
    for(int i=1;i<=q;i++)
    {
        int u = b[i],v = query[i].x,w= query[i].y;
        ans+=a[u]*w%mod;
        a[v]+=a[u],a[u]=0;
        a[v]%=mod;
    }
    cout<<ans%mod<<"\n";
    

}

signed main(){
    ios;
    int T = 1;
    //cin >> T;
    while(T --){
        solve();
    }
    return 0;
}

/*
2
SPR
SPSRRP
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3524kb

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: 3480kb

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: 0ms
memory: 3612kb

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: 3852kb

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'