Submission #932246

# Submission time Handle Problem Language Result Execution time Memory
932246 2024-02-23T06:18:31 Z hmm789 Shortcut (IOI16_shortcut) C++14
0 / 100
99 ms 380740 KB
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define INF 1000000000000000000
#define MOD 1000000007

#define int long long
vector<pair<int, int>> adj[2000000];
int dist[2000000], depth[2000000], p[2000000][21];

void dfs(int x, int pa, int d, int dep) {
    dist[x] = d;
    depth[x] = dep;
    p[x][0] = pa;
    for(int i = 1; i < 21; i++) {
        if(p[x][i-1] == -1) break;
        p[x][i] = p[p[x][i-1]][i-1];
    }
    for(auto i : adj[x]) if(i.first != pa) dfs(i.first, x, d+i.second, dep+1);
}

int lca(int a, int b) {
    if(depth[a] < depth[b]) swap(a, b);
    int h = depth[a]-depth[b];
    for(int i = 0; i < 21; i++) {
        if(h&(1<<i)) a = p[a][i];
    }
    if(a == b) return a;
    for(int i = 20; i >= 0; i--) {
        if(p[a][i] != p[b][i]) {
            a = p[a][i]; b = p[b][i];
        }
    }
    return p[a][0];
}

int dst(int x, int y) {
    return dist[x]+dist[y]-2*dist[lca(x,y)];
}
#undef int

long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) {
#define int long long
    int ans = INF;
    for(int k = 0; k < n-1; k++) {
        adj[k].push_back({k+1, l[k]});
        adj[k+1].push_back({k, l[k]});
    }
    for(int k = 0; k < n; k++) {
        adj[k].push_back({k+n, d[k]});
        adj[k+n].push_back({k, d[k]});
    }
    memset(p, -1, sizeof(p));
    dfs(0, -1, 0, 0);
    int ld[n], rd[n], ld2[n], rd2[n];
    for(int i = 0; i < n; i++) {
        ld[i] = 0;
        ld2[i] = 0;
        for(int j = 0; j <= i; j++) {
            ld[i] = max(ld[i], dst(j, i));
            ld[i] = max(ld[i], dst(j+n, i));
            ld2[i] = max(ld2[i], dst(j, i+n));
            ld2[i] = max(ld2[i], dst(j+n, i+n));
        }
    }
    for(int i = n-1; i >= 0; i--) {
        rd[i] = 0;
        rd2[i] = 0;
        for(int j = n-1; j >= i; j--) {
            rd[i] = max(rd[i], dst(j, i));
            rd[i] = max(rd[i], dst(j+n, i));
            rd2[i] = max(rd2[i], dst(j, i+n));
            rd2[i] = max(rd2[i], dst(j+n, i+n));
        }
    }
    int ds2[2*n][2*n];
    for(int i = 0; i < 2*n; i++) for(int j = 0; j < 2*n; j++) ds2[i][j] = dst(i, j);
    int ld3[n][n], rd3[n][n];
    memset(ld3, 0, sizeof(ld3));
    memset(rd3, 0, sizeof(rd3));
    for(int i = 0; i < n; i++) {
        for(int j = i; j < n; j++) {
            for(int k = i; k <= j; k++) {
                ld3[i][j] = max(ld3[i][j], ds2[i+n][k+n]);
            }
            for(int k = j; k >= i; k--) {
                rd3[i][j] = max(rd3[i][j], ds2[j+n][k+n]);
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            int tmp = 0;
            for(int k = 0; k < n; k++) {
                tmp = max({tmp, rd3[k][j-1], min(rd2[k], ds2[k+n][i] + c + rd[j])});
                tmp = max({tmp, ld3[i+1][k], min(ld2[k], ds2[k+n][j] + c + ld[i])});
            }
            ans = min(ans, tmp);
        }
    }
    return ans;
#undef int
}
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 378704 KB n = 4, 80 is a correct answer
2 Correct 76 ms 378724 KB n = 9, 110 is a correct answer
3 Correct 80 ms 380740 KB n = 4, 21 is a correct answer
4 Correct 69 ms 378508 KB n = 3, 4 is a correct answer
5 Correct 69 ms 378508 KB n = 2, 62 is a correct answer
6 Correct 67 ms 378708 KB n = 2, 3 is a correct answer
7 Correct 70 ms 378708 KB n = 3, 29 is a correct answer
8 Correct 73 ms 378740 KB n = 2, 3 is a correct answer
9 Correct 68 ms 378708 KB n = 2, 3 is a correct answer
10 Correct 68 ms 378568 KB n = 2, 2000000001 is a correct answer
11 Correct 67 ms 378708 KB n = 2, 3000000000 is a correct answer
12 Correct 67 ms 378704 KB n = 3, 3000000000 is a correct answer
13 Correct 66 ms 378692 KB n = 3, 3000000000 is a correct answer
14 Incorrect 66 ms 378708 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -