Submission #210543

# Submission time Handle Problem Language Result Execution time Memory
210543 2020-03-17T16:36:57 Z Nucleist Dreaming (IOI13_dreaming) C++14
14 / 100
1000 ms 22264 KB
#include "dreaming.h"
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int n;
int dp[100001];
vector<pair<int,int>>tr[100001];
bool vis[100001];
map<dos,int>ga;
int solve(int node,int p)
{
    int fat=0;
    vis[node]=1;
    for(auto it:tr[node])
    {
        if(it.first!=p)
        {
            fat=max(fat,it.second+solve(it.first,node));
        }
    }
    return dp[node]=fat;
}
int sol=0;
int ans;
set<int>kal;
void solve1(int node,int p,int besti)
{
    dp[node]=max(dp[node],besti);
    ans=min(dp[node],ans);
    set<pair<int,int>>gg;
    for(auto it:tr[node])
    {
        if(it.first!=p)
        {
            gg.insert({-(dp[it.first]+it.second),it.first});
        }
    }
    for(auto it:gg)
    {
        int p1=besti;
        int p2=0;
        auto u=it;
        gg.erase(it);
        if(gg.size()>0)
        {
        auto k =(*gg.begin());
        p2=-k.first;
        }
        if(u.second>=0 && u.second<n)solve1(u.second,node,max(p1,p2)+ga[{min(node,u.second),max(node,u.second)}]);
        gg.insert(u);
    }
    return;
}
int besti=0;
int far=0;
int nodi=0;
void dfs(int node,int p)
{
    vis[node]=1;
    if(far>besti)
    {
        besti=far;
        nodi=node;
    }
    for (auto it:tr[node])
    {
        if(it.first!=p)
            {
            far+=it.second;
            dfs(it.first,node);
            far-=it.second;
            }
    }
}
void dfs1(int node,int p)
{
    if(far>besti)
    {
        besti=far;
        nodi=node;
    }
    for (auto it:tr[node])
    {
        if(it.first!=p)
            {
            far+=it.second;
            dfs1(it.first,node);
            far-=it.second;
            }
    }
}
int diameter(int root)
{
    besti=0;
    dfs(root,-1);
    besti=0;
    dfs1(nodi,-1);
    return besti;
}
int step()
{
    int ans=0;
    memset(vis,0,sizeof vis);
    for (int i = 0; i < n; ++i)
    {
        if(!vis[i])
        {
            ans=max(ans,diameter(i));
        }
    }
    return ans;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
	flash;
	n=N;
	//debug(n);
	ans=pow(10,9);
    for (int i = 0; i < M; ++i)
    {
        int x=A[i];
        int y=B[i];
        int z=T[i];
        //debugs(x,y);
        tr[x].pb({y,z});
        tr[y].pb({x,z});
        ga[{min(x,y),max(x,y)}]=z;
    }
    sol=max(step(),sol);
    memset(vis,0,sizeof vis);
    for (int i = 0; i < n; ++i)
    {
        if(!vis[i])
        {
            solve(i,-1);
            solve1(i,-1,0);
            kal.insert(-ans);
            ans=pow(10,9);
        }
    }
    if(kal.size()>1)
    {
        auto u=(*kal.begin());
        kal.erase(u);
        auto k=(*kal.begin());
        sol=max(-u+L+-k,sol);
    }
    if(kal.size()>1)
    {
        auto u=(*kal.begin());
        kal.erase(u);
        auto k=(*kal.begin());
        sol=max(-u+L*2+-k,sol);
    }
    return sol;
}
//code the AC sol !
// BS/queue/map

Compilation message

dreaming.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
dreaming.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
# Verdict Execution time Memory Grader output
1 Correct 175 ms 22264 KB Output is correct
2 Correct 177 ms 21496 KB Output is correct
3 Correct 104 ms 18936 KB Output is correct
4 Correct 22 ms 5624 KB Output is correct
5 Correct 18 ms 4344 KB Output is correct
6 Correct 35 ms 7032 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 74 ms 10888 KB Output is correct
9 Correct 105 ms 15608 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 171 ms 16632 KB Output is correct
12 Correct 200 ms 19448 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 22264 KB Output is correct
2 Correct 177 ms 21496 KB Output is correct
3 Correct 104 ms 18936 KB Output is correct
4 Correct 22 ms 5624 KB Output is correct
5 Correct 18 ms 4344 KB Output is correct
6 Correct 35 ms 7032 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 74 ms 10888 KB Output is correct
9 Correct 105 ms 15608 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 171 ms 16632 KB Output is correct
12 Correct 200 ms 19448 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1099 ms 2808 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 22264 KB Output is correct
2 Correct 177 ms 21496 KB Output is correct
3 Correct 104 ms 18936 KB Output is correct
4 Correct 22 ms 5624 KB Output is correct
5 Correct 18 ms 4344 KB Output is correct
6 Correct 35 ms 7032 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 74 ms 10888 KB Output is correct
9 Correct 105 ms 15608 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 171 ms 16632 KB Output is correct
12 Correct 200 ms 19448 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1099 ms 2808 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 7416 KB Output is correct
2 Correct 52 ms 7544 KB Output is correct
3 Correct 52 ms 7416 KB Output is correct
4 Correct 54 ms 7416 KB Output is correct
5 Correct 51 ms 7420 KB Output is correct
6 Correct 56 ms 7672 KB Output is correct
7 Correct 53 ms 7672 KB Output is correct
8 Correct 50 ms 7288 KB Output is correct
9 Correct 49 ms 7288 KB Output is correct
10 Correct 57 ms 7548 KB Output is correct
11 Correct 6 ms 2808 KB Output is correct
12 Correct 11 ms 3192 KB Output is correct
13 Correct 11 ms 3320 KB Output is correct
14 Correct 10 ms 3192 KB Output is correct
15 Correct 9 ms 3192 KB Output is correct
16 Incorrect 9 ms 3192 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 22264 KB Output is correct
2 Correct 177 ms 21496 KB Output is correct
3 Correct 104 ms 18936 KB Output is correct
4 Correct 22 ms 5624 KB Output is correct
5 Correct 18 ms 4344 KB Output is correct
6 Correct 35 ms 7032 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 74 ms 10888 KB Output is correct
9 Correct 105 ms 15608 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 171 ms 16632 KB Output is correct
12 Correct 200 ms 19448 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1091 ms 10856 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 22264 KB Output is correct
2 Correct 177 ms 21496 KB Output is correct
3 Correct 104 ms 18936 KB Output is correct
4 Correct 22 ms 5624 KB Output is correct
5 Correct 18 ms 4344 KB Output is correct
6 Correct 35 ms 7032 KB Output is correct
7 Correct 6 ms 2808 KB Output is correct
8 Correct 74 ms 10888 KB Output is correct
9 Correct 105 ms 15608 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 171 ms 16632 KB Output is correct
12 Correct 200 ms 19448 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1099 ms 2808 KB Time limit exceeded
15 Halted 0 ms 0 KB -