QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296658#5073. Elden Ring_LAP_WA 103ms7976kbC++143.7kb2024-01-03 12:42:062024-01-03 12:42:07

Judging History

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

  • [2024-01-03 12:42:07]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:7976kb
  • [2024-01-03 12:42:06]
  • 提交

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();
        if(_ == 525) {
            cout << n << ' ' << m << ' ' << A << ' ' << B << '\n';
            for(int i = 1; i <= n; i ++)
                for(int j = h[i]; j != -1; j = ne[j])
                    if(i < e[j]) cout << i << ' ' << e[j] << '\n';
            for(int i = 1; i <= n; i ++) cout << l[i] << " \n"[i == n];
        }
    }

    return 0;
}

详细

Test #1:

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

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: 103ms
memory: 7976kb

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:

10 10 78243 73166
1 2
1 5
1 4
2 7
2 3
4 6
5 8
6 9
7 9
7 10
186663 119822 39982 137640 80774 38548 23495 164552 8666 75130

result:

wrong answer 1st numbers differ - expected: '-1', found: '10'