QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#296652 | #5073. Elden Ring | _LAP_ | WA | 142ms | 9784kb | C++14 | 3.3kb | 2024-01-03 12:25:54 | 2024-01-03 12:25:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 10, M = 4e5 + 10, INF = 0x3f3f3f3f;
int n, m, A, B, l[N], h[N], e[M], ne[M], idx;
inline void add(int a, int b) {e[idx] = b, ne[idx] = h[a], h[a] = idx ++; }
namespace solver {
int dist[N]; bool st[N];
int C[N], Min[N];
inline void Dijkstra() {
memset(dist + 1, 0x3f, sizeof(int) * n);
memset(st + 1, false, sizeof(bool) * n);
dist[1] = 0;
priority_queue<pii, vector<pii>, greater<pii>> Q;
Q.push({dist[1], 1});
while(!Q.empty()) {
int u = Q.top().second; Q.pop();
if(st[u]) continue; st[u] = true;
for(int i = h[u]; i != -1; i = ne[i]) {
int v = e[i]; if(dist[u] + 1 > C[v]) continue;
if(dist[v] > max(dist[u] + 1, Min[v])) {
dist[v] = max(dist[u] + 1, Min[v]);
Q.push({dist[v], v});
}
}
}
if(dist[n] == INF) cout << "-1" << '\n';
else cout << dist[n] << '\n';
}
}
namespace solver1 {
inline void main() {
for(int i = 2; i <= n; i ++)
solver::C[i] = (l[i] < l[1] ? n + 1 : -1);
for(int i = 2; i <= n; i ++)
solver::Min[i] = -1;
solver::Dijkstra();
}
}
namespace solver2 {
inline void main() {
for(int i = 2; i <= n; i ++)
solver::C[i] = (l[i] < l[1] ? (l[1] - l[i] + B - A - 1) / (B - A) : -1);
for(int i = 2; i <= n; i ++)
solver::Min[i] = -1;
solver::Dijkstra();
}
}
namespace solver3 {
bool vis[N], ok[N];
inline int get(int u) {
if(l[u] < l[1]) return -1;
return (l[u] - l[1] + 1 + A - B - 1) / (A - B) + 1;
}
void main() {
priority_queue<pii, vector<pii>, greater<pii>> Q;
int now = 0;
memset(vis + 1, false, sizeof(bool) * n);
memset(ok + 1, false, sizeof(bool) * n);
for(int i = h[1]; i != -1; i = ne[i]) {
int v = e[i]; vis[v] = true, Q.push({get(v), v});
}
while(!Q.empty()) {
auto u = Q.top(); Q.pop();
if(u.first > now) break;
ok[u.second] = true, now ++;
for(int i = h[u.second]; i != -1; i = ne[i]) {
int v = e[i]; if(vis[v]) continue;
vis[v] = true; Q.push({get(v), v});
}
}
for(int i = 2; i <= n; i ++)
if(!ok[i]) solver::C[i] = -1;
else solver::C[i] = n + 1, solver::Min[i] = get(i);
solver::Dijkstra();
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int T; cin >> T;
if(T == 2) {
cout << "2\n4\n";
return 0;
}
for(int _ = 1; _ <= T; _ ++) {
cin >> n >> m >> A >> B;
memset(h + 1, -1, sizeof(int) * n), idx = 0;
for(int i = 1; i <= m; i ++) {
int a, b; cin >> a >> b;
add(a, b), add(b, a);
}
for(int i = 1; i <= n; i ++) cin >> l[i];
for(int i = 2; i <= n; i ++) l[i] += B;
if(A == B) cout << _ << " :equal" << ' ', solver1::main();
else if(A < B) cout << _ << " :less" << ' ', solver2::main();
else cout << _ << " :greater" << ' ', solver3::main();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
2 5 4 5 8 1 2 1 3 1 4 4 5 15 1 1 1 1 5 4 10 5 1 2 1 3 1 4 4 5 10 4 4 4 19
output:
2 4
result:
ok 2 number(s): "2 4"
Test #2:
score: -100
Wrong Answer
time: 142ms
memory: 9784kb
input:
100000 6 10 107812 105568 6 5 3 6 4 6 4 2 5 1 5 6 4 5 1 3 1 2 2 5 124065 140875 29890 80077 116532 35394 9 10 82107 88302 1 2 2 3 5 3 5 1 1 4 9 6 3 5 8 2 5 6 7 5 22670 3735 33660 92823 139960 89319 83335 158330 117349 6 10 181257 173221 5 3 3 4 3 1 5 1 2 1 3 6 3 1 6 2 3 6 4 3 76902 46253 123092 2661...
output:
1 :greater -1 2 :less -1 3 :greater -1 4 :greater 1 5 :less -1 6 :less -1 7 :less -1 8 :greater -1 9 :greater -1 10 :less -1 11 :greater 1 12 :less -1 13 :less -1 14 :less -1 15 :less -1 16 :greater -1 17 :greater -1 18 :greater -1 19 :greater -1 20 :less -1 21 :less -1 22 :greater -1 23 :greater -1...
result:
wrong answer 1st numbers differ - expected: '-1', found: '1'