QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296655#5073. Elden Ring_LAP_WA 103ms7660kbC++143.7kb2024-01-03 12:33:562024-01-03 12:33:57

Judging History

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

  • [2024-01-03 12:33:57]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:7660kb
  • [2024-01-03 12:33:56]
  • 提交

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

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

7 10 24660 15016
1 7
1 4
1 3
1 2
2 1
3 6
3 7
3 1
3 6
3 5
4 1
5 3
5 6
6 3
6 7
6 3
6 5
7 1
7 3
7 6
55157 30303 165160 155608 126317 35427 47790

result:

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