Submission #575784

# Submission time Handle Problem Language Result Execution time Memory
575784 2022-06-11T09:14:24 Z Mazaalai Dreaming (IOI13_dreaming) C++17
32 / 100
67 ms 17080 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define ALL(x) x.begin(),x.end()
using namespace std;
using VI = vector <int>;
using PII = pair <int, int>;
const int N = 1e5+5;
vector <PII> paths[N];
bool vis[N];
int n, m, L, sizes[N], len;
PII dp[N];
 
PII getFarthest(int pos, int par = 0) {
    dp[pos] = {0, pos};
    for (auto [a, b] : paths[pos]) {
        if (a == par) continue;
        PII tmp = getFarthest(a, pos);
        if (dp[pos].ff < tmp.ff + b) dp[pos] = {tmp.ff + b, tmp.ss};
    }
    return dp[pos];
}
int getSizes(int pos, int par = 0) {
    vis[pos] = 1;
    for (auto [a, b] : paths[pos]) {
        if (a == par) continue;
        sizes[pos] = max(sizes[pos], b + getSizes(a, pos));
    }
    return sizes[pos];
}
VI findCentroid(int pos, int par = 0, int pre = 0) {
    int suf = len - pre;
    VI res = {pos, pre, suf};
    for (auto [a, b] : paths[pos]) {
        if (a == par) continue;
        int x = pre+b, y = sizes[a];
        if (max(pre, suf) >= max(x, y)) {
            VI tmp = findCentroid(a, pos, pre+b);
            if (max(pre, suf) > max(tmp[1], tmp[2])) res = tmp;
        }
    }
    return res;
}
VI getCentroid(int pos) {
    len = getSizes(pos);
    return findCentroid(pos);
}
int travelTime(int _N, int _M, int _L, int _A[], int _B[], int _T[]) {
    n = _N;
    m = _M;
    L = _L;
    vector <int> pts = {-1, -1, -1, -1};
    for (int i = 0; i < _M; i++) {
        // paths[_A[i]].pb({_B[i], _T[i]});
        // paths[_B[i]].pb({_A[i], _T[i]});
        paths[_A[i]+1].pb({_B[i]+1, _T[i]});
        paths[_B[i]+1].pb({_A[i]+1, _T[i]});
    }
    int res = 0, maxOnePoint = 0;
    for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        PII tmp = getFarthest(i);
        VI point = getCentroid(tmp.ss);
        maxOnePoint = max(maxOnePoint, len);
        if (point[1] < point[2]) swap(point[1], point[2]);
         // cout << '\t';for (int i = 0; i < 3; i++) cout << point[i] << " \n"[i==2];
        pts[0] = (max(point[1], point[2]));
        sort(ALL(pts));
        // cout << i-1 << ": " << point[0]-1 << ' ' << point[1] << ' ' << point[2] << '\n';
        // cout << i << ": " << point[0] << ' ' << point[1] << ' ' << point[2] << '\n';
    }
    if (pts[2] > -1) res = max(res, pts[2] + pts[3] + L);
    if (pts[1] > -1) res = max(res, pts[1] + pts[2] + 2*L);
 
    res = max(res, maxOnePoint);
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 17080 KB Output is correct
2 Correct 47 ms 17072 KB Output is correct
3 Correct 46 ms 12040 KB Output is correct
4 Correct 7 ms 4656 KB Output is correct
5 Correct 9 ms 3668 KB Output is correct
6 Correct 12 ms 5716 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 21 ms 7288 KB Output is correct
9 Correct 33 ms 9508 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 46 ms 11360 KB Output is correct
12 Correct 54 ms 14136 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 17080 KB Output is correct
2 Correct 47 ms 17072 KB Output is correct
3 Correct 46 ms 12040 KB Output is correct
4 Correct 7 ms 4656 KB Output is correct
5 Correct 9 ms 3668 KB Output is correct
6 Correct 12 ms 5716 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 21 ms 7288 KB Output is correct
9 Correct 33 ms 9508 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 46 ms 11360 KB Output is correct
12 Correct 54 ms 14136 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Incorrect 1 ms 2644 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6192 KB Output is correct
2 Correct 23 ms 6112 KB Output is correct
3 Correct 21 ms 6100 KB Output is correct
4 Correct 20 ms 6076 KB Output is correct
5 Correct 22 ms 6180 KB Output is correct
6 Correct 21 ms 6396 KB Output is correct
7 Correct 28 ms 6324 KB Output is correct
8 Correct 25 ms 6116 KB Output is correct
9 Correct 20 ms 6096 KB Output is correct
10 Correct 20 ms 6312 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 7 ms 3796 KB Output is correct
13 Correct 6 ms 3924 KB Output is correct
14 Correct 6 ms 3784 KB Output is correct
15 Correct 7 ms 3796 KB Output is correct
16 Correct 6 ms 3844 KB Output is correct
17 Correct 6 ms 3636 KB Output is correct
18 Correct 6 ms 3924 KB Output is correct
19 Correct 10 ms 3804 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 7 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Incorrect 1 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 17080 KB Output is correct
2 Correct 47 ms 17072 KB Output is correct
3 Correct 46 ms 12040 KB Output is correct
4 Correct 7 ms 4656 KB Output is correct
5 Correct 9 ms 3668 KB Output is correct
6 Correct 12 ms 5716 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 21 ms 7288 KB Output is correct
9 Correct 33 ms 9508 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 46 ms 11360 KB Output is correct
12 Correct 54 ms 14136 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Incorrect 1 ms 2644 KB Output isn't correct
17 Halted 0 ms 0 KB -