Submission #340114

# Submission time Handle Problem Language Result Execution time Memory
340114 2020-12-26T23:07:21 Z iliccmarko Dreaming (IOI13_dreaming) C++14
18 / 100
74 ms 19092 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
int maksd;
const int N = 1e5 + 5;
int vidjen[N];
vector<vector<pair<int, int > > > g(N);
vector<int> v;
int mm, s;
vector<vector<pair<int, int> > > path(N);

void najdalji(int u, int pret, int d)
{
    vidjen[u] = 1;
    if(d>=mm)
    {
        mm = d;
        s = u;
    }
    for(auto x : g[u])
    {
        if(x.first==pret) continue;
        najdalji(x.first, u, x.second+d);
    }
}

bool get_path(int u, int pret, int k, int parent, int d)
{
    if(u==k)
    {
        path[parent].pb({u, d});
        return true;
    }
    for(auto x : g[u])
    {
        if(x.first==pret) continue;
        if(get_path(x.first, u, k, parent, x.second))
        {
            path[parent].pb({u, d});
            return true;
        }
    }
    return false;
}


int travelTime(int n, int m, int l, int a[], int b[], int t[])
{
    for(int i = 0;i<m;i++)
    {
        int x = a[i];
        int y = b[i];
        int l = t[i];
        g[x].pb({y, l});
        g[y].pb({x, l});
    }
    for(int i = 1;i<=n;i++)
    {
        if(vidjen[i]) continue;
        mm = 0;
        s = i;
        int l1;
        najdalji(i, -1, 0);
        l1 = s;
        mm = 0;
        s = l1;
        int l2;
        najdalji(l1, -1, 0);
        l2 = s;
        get_path(l1, -1, l2, i, 0);
        int sum = 0;
        int c;
        int mini = INF;
        int m2 = 0;
        int p = 0;
        for(auto x : path[i]) sum += x.second;
        for(auto x : path[i])
        {
            p += x.second;
            if(max(p, abs(sum - p)) < mini)
            {
                m2 = max(p, abs(sum - p));
                mini = max(p, abs(sum - p));
                c = x.first;
            }
        }
        maksd = max(maksd, sum);
        v.pb(m2);
    }
    sort(all(v), greater<int>());
    int ans = maksd;
    if(len(v)==1)
    {
        return ans;
    }
    ans = max(ans, v[0]+v[1]+l);
    if(len(v)>=3)
    {
        ans = max(ans, v[1] + v[2] + 2*l);
    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:85:13: warning: variable 'c' set but not used [-Wunused-but-set-variable]
   85 |         int c;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19092 KB Output is correct
2 Correct 68 ms 19048 KB Output is correct
3 Correct 40 ms 14056 KB Output is correct
4 Correct 11 ms 7072 KB Output is correct
5 Correct 14 ms 6124 KB Output is correct
6 Correct 17 ms 8168 KB Output is correct
7 Incorrect 4 ms 5100 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19092 KB Output is correct
2 Correct 68 ms 19048 KB Output is correct
3 Correct 40 ms 14056 KB Output is correct
4 Correct 11 ms 7072 KB Output is correct
5 Correct 14 ms 6124 KB Output is correct
6 Correct 17 ms 8168 KB Output is correct
7 Incorrect 4 ms 5100 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19092 KB Output is correct
2 Correct 68 ms 19048 KB Output is correct
3 Correct 40 ms 14056 KB Output is correct
4 Correct 11 ms 7072 KB Output is correct
5 Correct 14 ms 6124 KB Output is correct
6 Correct 17 ms 8168 KB Output is correct
7 Incorrect 4 ms 5100 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 9960 KB Output is correct
2 Correct 34 ms 9960 KB Output is correct
3 Correct 35 ms 9960 KB Output is correct
4 Correct 42 ms 10108 KB Output is correct
5 Correct 38 ms 9832 KB Output is correct
6 Correct 34 ms 10472 KB Output is correct
7 Correct 38 ms 10088 KB Output is correct
8 Correct 30 ms 9832 KB Output is correct
9 Correct 33 ms 9832 KB Output is correct
10 Correct 42 ms 10088 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 19 ms 8932 KB Output is correct
13 Correct 20 ms 8932 KB Output is correct
14 Correct 14 ms 8932 KB Output is correct
15 Correct 14 ms 8932 KB Output is correct
16 Correct 17 ms 8932 KB Output is correct
17 Correct 14 ms 8932 KB Output is correct
18 Correct 20 ms 8932 KB Output is correct
19 Correct 17 ms 8932 KB Output is correct
20 Correct 3 ms 4972 KB Output is correct
21 Correct 3 ms 4972 KB Output is correct
22 Correct 4 ms 5100 KB Output is correct
23 Correct 14 ms 8932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19092 KB Output is correct
2 Correct 68 ms 19048 KB Output is correct
3 Correct 40 ms 14056 KB Output is correct
4 Correct 11 ms 7072 KB Output is correct
5 Correct 14 ms 6124 KB Output is correct
6 Correct 17 ms 8168 KB Output is correct
7 Incorrect 4 ms 5100 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 19092 KB Output is correct
2 Correct 68 ms 19048 KB Output is correct
3 Correct 40 ms 14056 KB Output is correct
4 Correct 11 ms 7072 KB Output is correct
5 Correct 14 ms 6124 KB Output is correct
6 Correct 17 ms 8168 KB Output is correct
7 Incorrect 4 ms 5100 KB Output isn't correct
8 Halted 0 ms 0 KB -