Submission #210542

# Submission time Handle Problem Language Result Execution time Memory
210542 2020-03-17T16:36:10 Z Nucleist Dreaming (IOI13_dreaming) C++14
14 / 100
1000 ms 23416 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[])
{
	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 180 ms 23416 KB Output is correct
2 Correct 181 ms 22776 KB Output is correct
3 Correct 109 ms 19960 KB Output is correct
4 Correct 22 ms 5812 KB Output is correct
5 Correct 20 ms 4472 KB Output is correct
6 Correct 33 ms 7160 KB Output is correct
7 Correct 7 ms 2808 KB Output is correct
8 Correct 72 ms 11384 KB Output is correct
9 Correct 104 ms 16248 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 170 ms 17784 KB Output is correct
12 Correct 201 ms 20472 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 23416 KB Output is correct
2 Correct 181 ms 22776 KB Output is correct
3 Correct 109 ms 19960 KB Output is correct
4 Correct 22 ms 5812 KB Output is correct
5 Correct 20 ms 4472 KB Output is correct
6 Correct 33 ms 7160 KB Output is correct
7 Correct 7 ms 2808 KB Output is correct
8 Correct 72 ms 11384 KB Output is correct
9 Correct 104 ms 16248 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 170 ms 17784 KB Output is correct
12 Correct 201 ms 20472 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1079 ms 2808 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 180 ms 23416 KB Output is correct
2 Correct 181 ms 22776 KB Output is correct
3 Correct 109 ms 19960 KB Output is correct
4 Correct 22 ms 5812 KB Output is correct
5 Correct 20 ms 4472 KB Output is correct
6 Correct 33 ms 7160 KB Output is correct
7 Correct 7 ms 2808 KB Output is correct
8 Correct 72 ms 11384 KB Output is correct
9 Correct 104 ms 16248 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 170 ms 17784 KB Output is correct
12 Correct 201 ms 20472 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1079 ms 2808 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 7800 KB Output is correct
2 Correct 53 ms 7928 KB Output is correct
3 Correct 53 ms 7800 KB Output is correct
4 Correct 53 ms 7800 KB Output is correct
5 Correct 54 ms 7800 KB Output is correct
6 Correct 56 ms 8184 KB Output is correct
7 Correct 56 ms 8056 KB Output is correct
8 Correct 55 ms 7800 KB Output is correct
9 Correct 53 ms 7676 KB Output is correct
10 Correct 57 ms 8056 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 10 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 180 ms 23416 KB Output is correct
2 Correct 181 ms 22776 KB Output is correct
3 Correct 109 ms 19960 KB Output is correct
4 Correct 22 ms 5812 KB Output is correct
5 Correct 20 ms 4472 KB Output is correct
6 Correct 33 ms 7160 KB Output is correct
7 Correct 7 ms 2808 KB Output is correct
8 Correct 72 ms 11384 KB Output is correct
9 Correct 104 ms 16248 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 170 ms 17784 KB Output is correct
12 Correct 201 ms 20472 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1098 ms 11000 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 180 ms 23416 KB Output is correct
2 Correct 181 ms 22776 KB Output is correct
3 Correct 109 ms 19960 KB Output is correct
4 Correct 22 ms 5812 KB Output is correct
5 Correct 20 ms 4472 KB Output is correct
6 Correct 33 ms 7160 KB Output is correct
7 Correct 7 ms 2808 KB Output is correct
8 Correct 72 ms 11384 KB Output is correct
9 Correct 104 ms 16248 KB Output is correct
10 Correct 7 ms 2936 KB Output is correct
11 Correct 170 ms 17784 KB Output is correct
12 Correct 201 ms 20472 KB Output is correct
13 Correct 7 ms 2936 KB Output is correct
14 Execution timed out 1079 ms 2808 KB Time limit exceeded
15 Halted 0 ms 0 KB -