QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546431#8038. Hammer to FallqwqpmpWA 37ms11876kbC++173.4kb2024-09-04 02:17:362024-09-04 02:17:37

Judging History

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

  • [2024-09-04 02:17:37]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:11876kb
  • [2024-09-04 02:17:36]
  • 提交

answer

// 日丽风和, 希望大家可以平安归来;
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("inline")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n'
#define ayy(x) array<int,x>
#define ys(x) (x?"Yes":"No")
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand()%x; }
const ll mod=1000000007,off=5;
const int MAXN=1e5+10,B=500;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// head

template<int MOD, int RT> struct mint {
    static const int mod = MOD;
    static constexpr mint rt() { return RT; } // primitive root for FFT
    int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
    mint():v(0) {}
    mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
        if (v < 0) v += MOD; }
    bool operator==(const mint& o) const {
        return v == o.v; }
    friend bool operator!=(const mint& a, const mint& b) { 
        return !(a == b); }
    friend bool operator<(const mint& a, const mint& b) { 
        return a.v < b.v; }
   
    mint& operator+=(const mint& o) { 
        if ((v += o.v) >= MOD) v -= MOD; 
        return *this; }
    mint& operator-=(const mint& o) { 
        if ((v -= o.v) < 0) v += MOD; 
        return *this; }
    mint& operator*=(const mint& o) { 
        v = int((ll)v*o.v%MOD); return *this; }
    mint& operator/=(const mint& o) { return (*this) *= inv(o); }
    friend mint pow(mint a, ll p) {
        mint ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans; }
    friend mint inv(const mint& a) { assert(a.v != 0); 
        return pow(a,MOD-2); }
        
    mint operator-() const { return mint(-v); }
    mint& operator++() { return *this += 1; }
    mint& operator--() { return *this -= 1; }
    friend mint operator+(mint a, const mint& b) { return a += b; }
    friend mint operator-(mint a, const mint& b) { return a -= b; }
    friend mint operator*(mint a, const mint& b) { return a *= b; }
    friend mint operator/(mint a, const mint& b) { return a /= b; }
};
 
const int MOD=998244353; 
using mi = mint<MOD,5>; // 5 is primitive root for both common mods

struct edge{
	int v,w;
};
vector<edge> e[MAXN];
int a[MAXN],b[MAXN];
mi f[MAXN],f2[MAXN];
int n,m,q;

signed main(){
	// freopen("qwq.in","r",stdin);
	// freopen("qwq.out","w",stdout);

	scanf("%d%d%d",&n,&m,&q);
	rep(i,1,n+1) scanf("%d",&a[i]);
	rep(i,1,m+1) {
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		e[u].pb((edge){v,w});
		e[v].pb((edge){u,w});
	}
	rep(i,1,q+1) scanf("%d",&b[i]);
	per(i,1,q+1) {
		if (SZ(e[b[i]])>=B) {
			f[b[i]]=f2[b[i]];
		}
		else {
			mi ans=0;
			for (auto [x,y] : e[b[i]]) {
				if (ans.v==0) ans=f[x]+y;
				else ans=min(ans,f[x]+y);
			}
			f2[b[i]]=f[b[i]]=ans;
			for (auto [x,y] : e[b[i]]) 
				if (SZ(e[x])>=B) f2[x]=min(f2[x],ans+y);
		}
	}
	mi ans=0;
	rep(i,1,n+1) ans+=f[i]*a[i];
	printf("%d",ans.v);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7744kb

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

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

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: 0
Accepted
time: 2ms
memory: 8024kb

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:

609241

result:

ok single line: '609241'

Test #5:

score: -100
Wrong Answer
time: 37ms
memory: 11876kb

input:

100000 100000 100000
134299012 740620432 241626312 533601686 901212368 274154852 46613593 72208460 685661661 930069933 934386896 140544225 900179749 8735320 54649110 922673925 450551589 517879800 773426781 410723403 783459037 344315202 75310230 122339501 113898579 646500753 18238713 119326471 969272...

output:

51004422

result:

wrong answer 1st lines differ - expected: '641103242', found: '51004422'