QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#526#317894#8038. Hammer to Fallship2077ship2077Failed.2024-01-30 14:20:352024-01-30 14:20:35

Details

Extra Test:

Invalid Input

input:

600 96000 600
-8388608 -16777216 -25165824 -33554432 -41943040 -50331648 -58720256 -67108864 -75497472 -83886080 -92274688 -100663296 -109051904 -117440512 -125829120 -134217728 -142606336 -150994944 -159383552 -167772160 -176160768 -184549376 -192937984 -201326592 -209715200 -218103808 -226492416 -...

output:


result:

FAIL Integer parameter [name=a] equals to -8388608, violates the range [1, 10^9] (stdin, line 2)

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;
}