QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#527#317894#8038. Hammer to Fallship2077ship2077Failed.2024-01-30 14:22:162024-01-30 14:22:17

Details

Extra Test:

Invalid Input

input:

600 96000 600
999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991 999999990 999999989 999999988 999999987 999999986 999999985 999999984 999999983 999999982 999999981 999999980 999999979 999999978 999999977 999999976 999999975 999999974 999999973 999999972 999999...

output:


result:

FAIL Unexpected character #10, but ' ' expected (stdin, line 96003)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317894#8038. Hammer to Fallship2077RE 626ms710352kbC++141.4kb2024-01-29 21:42:222024-01-30 14:24:09

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int M=1e5+5,mod=998244353;
tuple<ll,int,int>res[500][M];
int n,m,q,x,y,z,ans,tot,block;
vector<pair<int,int>>g[M];ll dp[M];
int a[M],p[M],id[M],vec[M];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
void solve(int ql,int qr){
    for (int k=1;k<=tot;k++){ int x=vec[k],siz=0;
        for (auto [y,z]:g[x]) res[k][++siz]={dp[y]+z,y,z};
    	nth_element(res[k]+1,res[k]+block,res[k]+siz+1);
    }
    for (int i=qr;i>=ql;i--){
        int x=p[i];dp[x]=1ll<<60;
        if (g[x].size()<=block)
            for (auto [y,z]:g[x])
                dp[x]=min(dp[x],dp[y]+z);
        else for (int j=1;j<=block;j++)
            dp[x]=min(dp[x],dp[get<1>(res[id[x]][j])]+get<2>(res[id[x]][j]));
    }
}
int main(){
    n=read();m=read();q=read();
    for (int i=1;i<=n;i++) a[i]=read();
    for (int i=1;i<=m;i++){
        x=read();y=read();z=read();
        g[x].push_back({y,z});
        g[y].push_back({x,z});
    }
    block=(int)ceil(sqrt(m));
    for (int i=1;i<=n;i++)
        if (g[i].size()>block)
            vec[++tot]=i,id[i]=tot;
    for (int i=1;i<=q;i++) p[i]=read();
    for (int i=q;i>0;i-=block) solve(max(i-block,0)+1,i);
    for (int i=1;i<=n;i++) ans=(ans+dp[i]%mod*a[i])%mod;
    printf("%d\n",ans);
    return 0;
}