Submission #1070841

# Submission time Handle Problem Language Result Execution time Memory
1070841 2024-08-22T19:26:39 Z MohamedFaresNebili Closing Time (IOI23_closing) C++17
21 / 100
1000 ms 38268 KB
#include <bits/stdc++.h>
            #include "closing.h"

                    using namespace std;

                    vector<pair<int, long long>> adj[200005];
                    long long D[200005][2];
                    vector<long long> pL, pR, pM;
                    void dfs(int X, int p, int st) {
                        for(auto u : adj[X]) {
                            if(u.first == p) continue;
                            D[u.first][st] = D[X][st] + u.second;
                            dfs(u.first, X, st);
                        }
                    }
                    long long sum(int l, int r, vector<long long> arr) {
                        return arr[r] - (l > 0 ? arr[l - 1] : 0);
                    }

                    int max_score(int N, int X, int Y, long long K,
                        vector<int> U, vector<int> V, vector<int> W) {
                        pL.resize(N); pR.resize(N); pM.resize(N);
                        for(int l = 0; l < N; l++) D[l][0] = D[l][1] = 2e18 + 7, adj[l].clear();
                        for(int l = 0; l < N - 1; l++) {
                            adj[U[l]].push_back({V[l], W[l]});
                            adj[V[l]].push_back({U[l], W[l]});
                        }
                        if(X > Y) swap(X, Y);
                        D[X][0] = 0, D[Y][1] = 0;
                        dfs(X, X, 0); dfs(Y, Y, 1);
                        for(int l = 0; l < N; l++) {
                            pL[l] = D[l][0];
                            pR[l] = D[l][1];
                            pM[l] = min(D[l][0], D[l][1]);
                            if(l > 0) {
                                pL[l] += pL[l - 1];
                                pR[l] += pR[l - 1];
                                pM[l] += pM[l - 1];
                            }
                        }
                        int res = 0;
                        for(int l = 0; l < N; l++) {
                            for(int i = l; i < N; i++) {
                                int lo = l, hi = i;
                                long long calc = sum(l, i, pL) + sum(l, i, pR) - sum(l, i, pM);
                                if(calc > K) continue;
                                int cur = 2 * (i - l + 1);
                                while(lo > 0 || hi < N - 1) {
                                    if(lo == 0) {
                                        ++hi; calc += min(D[hi][0], D[hi][1]);
                                        if(calc > K) {
                                            hi--; break;
                                        }
                                      	cur++;
                                    }
                                    else if(hi == N - 1) {
                                        --lo; calc += min(D[lo][0], D[lo][1]);
                                        if(calc > K) {
                                            lo++; break;
                                        } cur++;
                                    }
                                    else {
                                        int a = lo - 1, b = hi + 1;
                                        long long x = min(D[a][0], D[a][1]);
                                        long long y = min(D[b][0], D[b][1]);
                                      	if(calc + min(x, y) > K) break;
                                      	cur++;
                                        if(x <= y) {
                                            calc += x; lo--;
                                        }
                                        else { calc += y; hi++; }
                                    }
                                }
                                if(X >= lo && Y <= hi) res = max(res, cur);
                            }
                        }

                        vector<int> belong(N, -1);
                        priority_queue<array<long long, 3>, vector<array<long long, 3>>, greater<array<long long, 3>>> pq;
                        pq.push({0, X, 0}); pq.push({0, Y, 1});
                        int cur = 0; long long calc = 0;
                        while(!pq.empty()) {
                            int a = pq.top()[1], st = pq.top()[2];
                            long long w = pq.top()[0]; pq.pop();
                            if(calc + w > K) break;
                            if(belong[a] != -1) continue;
                            belong[a] = st; calc += w; cur++;
                            if(a > 0) {
                                int b = a - 1;
                                if(belong[b] == -1) {
                                    array<long long, 3> arr = {D[b][st], b, st};
                                    pq.push(arr);
                                }
                            }
                            if(a < N - 1) {
                                int b = a + 1;
                                if(belong[b] == -1) {
                                    array<long long, 3> arr = {D[b][st], b, st};
                                    pq.push(arr);
                                }
                            }
                        }
                        res = max(res, cur);
                        return res;
                    }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 38268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Correct 1 ms 6232 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Correct 1 ms 6232 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5820 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5980 KB Output is correct
18 Correct 2 ms 6048 KB Output is correct
19 Correct 70 ms 6120 KB Output is correct
20 Correct 28 ms 5980 KB Output is correct
21 Correct 64 ms 5980 KB Output is correct
22 Correct 26 ms 5980 KB Output is correct
23 Correct 48 ms 5980 KB Output is correct
24 Correct 48 ms 6116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5976 KB Output is correct
2 Correct 2 ms 5976 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 2 ms 5980 KB Output is correct
10 Correct 1 ms 6232 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5820 KB Output is correct
15 Correct 2 ms 5976 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5980 KB Output is correct
18 Correct 2 ms 6048 KB Output is correct
19 Correct 70 ms 6120 KB Output is correct
20 Correct 28 ms 5980 KB Output is correct
21 Correct 64 ms 5980 KB Output is correct
22 Correct 26 ms 5980 KB Output is correct
23 Correct 48 ms 5980 KB Output is correct
24 Correct 48 ms 6116 KB Output is correct
25 Correct 11 ms 5980 KB Output is correct
26 Execution timed out 1098 ms 6492 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5976 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Incorrect 1 ms 5980 KB 1st lines differ - on the 1st token, expected: '9', found: '7'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5976 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 1 ms 6232 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5980 KB Output is correct
15 Correct 2 ms 5820 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 1 ms 5980 KB Output is correct
20 Correct 2 ms 5980 KB Output is correct
21 Incorrect 1 ms 5980 KB 1st lines differ - on the 1st token, expected: '9', found: '7'
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5976 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 1 ms 6232 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5980 KB Output is correct
15 Correct 2 ms 5820 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 2 ms 6048 KB Output is correct
20 Correct 70 ms 6120 KB Output is correct
21 Correct 28 ms 5980 KB Output is correct
22 Correct 64 ms 5980 KB Output is correct
23 Correct 26 ms 5980 KB Output is correct
24 Correct 48 ms 5980 KB Output is correct
25 Correct 48 ms 6116 KB Output is correct
26 Correct 1 ms 5980 KB Output is correct
27 Correct 2 ms 5980 KB Output is correct
28 Incorrect 1 ms 5980 KB 1st lines differ - on the 1st token, expected: '9', found: '7'
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5976 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 1 ms 6232 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5980 KB Output is correct
15 Correct 2 ms 5820 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 2 ms 6048 KB Output is correct
20 Correct 70 ms 6120 KB Output is correct
21 Correct 28 ms 5980 KB Output is correct
22 Correct 64 ms 5980 KB Output is correct
23 Correct 26 ms 5980 KB Output is correct
24 Correct 48 ms 5980 KB Output is correct
25 Correct 48 ms 6116 KB Output is correct
26 Correct 11 ms 5980 KB Output is correct
27 Execution timed out 1098 ms 6492 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5976 KB Output is correct
3 Correct 2 ms 5976 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 2 ms 5980 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 1 ms 6232 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 2 ms 5980 KB Output is correct
15 Correct 2 ms 5820 KB Output is correct
16 Correct 2 ms 5976 KB Output is correct
17 Correct 2 ms 5976 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 2 ms 6048 KB Output is correct
20 Correct 70 ms 6120 KB Output is correct
21 Correct 28 ms 5980 KB Output is correct
22 Correct 64 ms 5980 KB Output is correct
23 Correct 26 ms 5980 KB Output is correct
24 Correct 48 ms 5980 KB Output is correct
25 Correct 48 ms 6116 KB Output is correct
26 Correct 11 ms 5980 KB Output is correct
27 Execution timed out 1098 ms 6492 KB Time limit exceeded
28 Halted 0 ms 0 KB -