QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#543900 | #8038. Hammer to Fall | BaseAI | WA | 31ms | 21552kb | C++14 | 1.8kb | 2024-09-01 23:31:25 | 2024-09-01 23:31:25 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mp(a,b) make_pair(a,b)
using namespace std;
inline int read() {
int x = 0, f = 1; char ch = getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
typedef pair<int,int> pii;
const int N = 1e5+7;
const int INF = 1e9;
const int mod = 998244353;
int n,m,q;
vector<pii> E[N];
vector<pii> big[N]; //u 连了哪些大点
set<pii> g[N]; //大点u 的 f集合
void gmin(int &x,int y) {
x = min(x, y);
}
signed main()
{
n = read(), m = read(), q = read();
vector<int> deg(n+1, 0), a(n+1, 0);
for(int i=1;i<=n;++i) a[i] = read();
for(int i=1;i<=m;++i) {
int u = read(), v = read(), w = read();
E[u].push_back(mp(v, w));
E[v].push_back(mp(u, w));
++deg[u], ++deg[v];
}
int B = sqrt(m);
for(int i=1;i<=n;++i) {
if(deg[i] >= B) {
for(auto [v, w] : E[i]) {
big[v].push_back(mp(i, w));
g[i].insert(mp(w, v));
}
}
}
vector<int> b(q, 0);
for(int i=0;i<q;++i) b[i] = read();
vector<int> f(n+1, 0);
for(int i=q-1;i>=0;--i) {
int u = b[i], last = f[u];
f[u] = INF;
if(deg[u] <= B) {
for(auto [v, w] : E[u]) {
gmin(f[u], f[v]+w);
}
} else {
f[u] = (*g[u].begin()).first;
}
for(auto [v, w] : big[u]) {
g[v].erase(mp(last+w, u));
g[v].insert(mp(f[u]+w, u));
}
}
//for(int i=1;i<=n;++i) printf("%d ",f[i]);
//cout << endl;
int ans = 0;
for(int i=1;i<=n;++i) ans = (ans + a[i]*f[i]) % mod;
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 13060kb
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: 3ms
memory: 12964kb
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: 13028kb
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: 3ms
memory: 13012kb
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: 31ms
memory: 21552kb
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:
682850536
result:
wrong answer 1st lines differ - expected: '641103242', found: '682850536'