Submission #940243

# Submission time Handle Problem Language Result Execution time Memory
940243 2024-03-07T06:57:10 Z shenfe1 Dreaming (IOI13_dreaming) C++17
47 / 100
184 ms 22340 KB
#include <bits/stdc++.h>

#pragma optimize("Ofast")
#pragma target("avx2")

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll

const int MAX=1e5+15;
const ll inf=1e9;  
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

int binpow(int a,int n){
  if(!n)return 1;
  if(n%2==1)return a*binpow(a,n-1);
  int k=binpow(a,n/2);
  return k*k;
}

#include "dreaming.h"

int n;
int tin[MAX],tout[MAX],timer;
int use[MAX];
int d[MAX];
int rev[MAX];
vector<pii> g[MAX];
vector<int> vec;

void dfs1(int v){
  vec.pb(v);
  use[v]=1;
  for(auto to:g[v]){
    if(!use[to.F])dfs1(to.F);
  }
}

void dfs(int v,int p=-1){
  tin[v]=++timer;
  rev[timer]=v;
  for(auto to:g[v]){
    if(to.F!=p){
      d[to.F]=d[v]+to.S;
      dfs(to.F,v);
    }
  }
  tout[v]=timer;
}

int t[4*MAX],add[4*MAX];
int C;

void build(int v,int tl,int tr){
  add[v]=0;
  if(tl==tr){
    t[v]=d[rev[tl]];
    return;
  }
  int tm=(tl+tr)/2;
  build(2*v,tl,tm);
  build(2*v+1,tm+1,tr);
  t[v]=max(t[2*v],t[2*v+1]);
}

void push(int v){
  add[2*v]+=add[v];
  add[2*v+1]+=add[v];
  t[2*v]+=add[v];
  t[2*v+1]+=add[v];
  add[v]=0;
}

void update(int v,int tl,int tr,int l,int r,int x){
  if(l>r||tl>r||l>tr)return;
  if(l<=tl&&tr<=r){
    t[v]+=x;
    add[v]+=x;
    return;
  }
  int tm=(tl+tr)/2;
  push(v);
  update(2*v,tl,tm,l,r,x);
  update(2*v+1,tm+1,tr,l,r,x);
  t[v]=max(t[2*v],t[2*v+1]);
}

pii calc(int v,int p=-1){
  int ans=t[1];
  int ans1=t[1];
  // cout<<v<<" "<<t[1]<<"\n";
  for(auto to:g[v]){
    if(to.F==p)continue;
    update(1,1,C,tin[to.F],tout[to.F],-to.S);
    update(1,1,C,1,tin[to.F]-1,to.S);
    update(1,1,C,tout[to.F]+1,C,to.S);
    pii bf=calc(to.F,v);
    ans=max(ans,bf.F);
    ans1=min(ans1,bf.S);
    update(1,1,C,tin[to.F],tout[to.F],to.S);
    update(1,1,C,1,tin[to.F]-1,-to.S);
    update(1,1,C,tout[to.F]+1,C,-to.S);
  }
  // cout<<v<<" "<<ans<<" "<<t[1]<<"\n";
  return {ans,ans1};
}

pii solve(vector<int> ver){
  {
    timer=0;
    for(int i=1;i<=sz(ver);i++)rev[i]=0;
    for(int x:ver)d[x]=0;
    dfs(ver[0]);
  }
  C=sz(ver);
  build(1,1,C);
  pii res=calc(ver[0]);
  return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  // assert(M==N-2);
  n=N;
  for(int i=0;i<M;i++){
    g[A[i]+1].pb({B[i]+1,T[i]});
    g[B[i]+1].pb({A[i]+1,T[i]});
  }
  int mxD=0;
  int ans=0;
  vector<int> dep;
  for(int i=1;i<=n;i++){
    if(!use[i]){
      dfs1(i);
      pii bf=solve(vec);
      dep.pb(bf.S);
      mxD=max(mxD,bf.F);
      vec.clear();
    }
  }
  sort(all(dep));
  if(sz(dep)>=2)ans=max(ans,dep.back()+dep[sz(dep)-2]+L);
  if(sz(dep)>=3)ans=max(ans,dep[sz(dep)-2]+dep[sz(dep)-3]+L);
  return max(mxD,ans);
}

Compilation message

dreaming.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast")
      | 
dreaming.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
# Verdict Execution time Memory Grader output
1 Correct 121 ms 17444 KB Output is correct
2 Correct 121 ms 16944 KB Output is correct
3 Correct 106 ms 16116 KB Output is correct
4 Correct 16 ms 9816 KB Output is correct
5 Correct 11 ms 9308 KB Output is correct
6 Correct 26 ms 10580 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 49 ms 12048 KB Output is correct
9 Correct 53 ms 14340 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 102 ms 14708 KB Output is correct
12 Correct 109 ms 15828 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8652 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 17444 KB Output is correct
2 Correct 121 ms 16944 KB Output is correct
3 Correct 106 ms 16116 KB Output is correct
4 Correct 16 ms 9816 KB Output is correct
5 Correct 11 ms 9308 KB Output is correct
6 Correct 26 ms 10580 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 49 ms 12048 KB Output is correct
9 Correct 53 ms 14340 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 102 ms 14708 KB Output is correct
12 Correct 109 ms 15828 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 2 ms 8652 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 119 ms 17452 KB Output is correct
40 Correct 115 ms 16844 KB Output is correct
41 Correct 89 ms 16080 KB Output is correct
42 Correct 15 ms 9816 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 2 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 1 ms 8536 KB Output is correct
54 Correct 1 ms 8792 KB Output is correct
55 Correct 1 ms 8540 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 148 ms 13776 KB Output is correct
58 Correct 134 ms 13792 KB Output is correct
59 Correct 138 ms 13776 KB Output is correct
60 Correct 135 ms 13480 KB Output is correct
61 Correct 137 ms 13520 KB Output is correct
62 Correct 134 ms 13384 KB Output is correct
63 Correct 144 ms 13524 KB Output is correct
64 Correct 135 ms 13628 KB Output is correct
65 Correct 141 ms 13640 KB Output is correct
66 Correct 184 ms 13632 KB Output is correct
67 Correct 156 ms 13796 KB Output is correct
68 Correct 139 ms 13772 KB Output is correct
69 Correct 141 ms 13348 KB Output is correct
70 Correct 140 ms 13520 KB Output is correct
71 Correct 1 ms 8536 KB Output is correct
72 Correct 4 ms 8796 KB Output is correct
73 Correct 4 ms 8796 KB Output is correct
74 Correct 5 ms 8648 KB Output is correct
75 Correct 5 ms 8796 KB Output is correct
76 Correct 4 ms 8796 KB Output is correct
77 Correct 5 ms 8796 KB Output is correct
78 Correct 5 ms 8792 KB Output is correct
79 Correct 5 ms 8796 KB Output is correct
80 Correct 150 ms 13552 KB Output is correct
81 Correct 159 ms 13640 KB Output is correct
82 Correct 151 ms 13520 KB Output is correct
83 Correct 156 ms 13780 KB Output is correct
84 Correct 3 ms 8536 KB Output is correct
85 Correct 3 ms 8540 KB Output is correct
86 Correct 4 ms 8540 KB Output is correct
87 Correct 4 ms 8632 KB Output is correct
88 Correct 4 ms 8540 KB Output is correct
89 Correct 4 ms 8540 KB Output is correct
90 Correct 4 ms 8540 KB Output is correct
91 Correct 4 ms 8796 KB Output is correct
92 Correct 4 ms 8540 KB Output is correct
93 Correct 4 ms 8540 KB Output is correct
94 Correct 2 ms 8536 KB Output is correct
95 Correct 1 ms 8540 KB Output is correct
96 Correct 1 ms 8540 KB Output is correct
97 Correct 2 ms 8536 KB Output is correct
98 Correct 1 ms 8540 KB Output is correct
99 Correct 1 ms 8540 KB Output is correct
100 Correct 1 ms 8540 KB Output is correct
101 Correct 2 ms 8540 KB Output is correct
102 Correct 1 ms 8540 KB Output is correct
103 Correct 1 ms 8540 KB Output is correct
104 Correct 13 ms 9308 KB Output is correct
105 Correct 26 ms 10588 KB Output is correct
106 Correct 2 ms 8540 KB Output is correct
107 Correct 64 ms 12040 KB Output is correct
108 Correct 56 ms 14292 KB Output is correct
109 Correct 2 ms 8540 KB Output is correct
110 Correct 97 ms 14476 KB Output is correct
111 Correct 107 ms 15828 KB Output is correct
112 Correct 2 ms 8540 KB Output is correct
113 Correct 152 ms 22340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 11228 KB Output is correct
2 Incorrect 17 ms 11352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8536 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8652 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8536 KB Output is correct
27 Correct 3 ms 8540 KB Output is correct
28 Correct 3 ms 8652 KB Output is correct
29 Correct 2 ms 8540 KB Output is correct
30 Correct 3 ms 8540 KB Output is correct
31 Correct 3 ms 8540 KB Output is correct
32 Incorrect 2 ms 8540 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 17444 KB Output is correct
2 Correct 121 ms 16944 KB Output is correct
3 Correct 106 ms 16116 KB Output is correct
4 Correct 16 ms 9816 KB Output is correct
5 Correct 11 ms 9308 KB Output is correct
6 Correct 26 ms 10580 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 49 ms 12048 KB Output is correct
9 Correct 53 ms 14340 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 102 ms 14708 KB Output is correct
12 Correct 109 ms 15828 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 2 ms 8540 KB Output is correct
31 Correct 2 ms 8652 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8540 KB Output is correct
38 Correct 2 ms 8540 KB Output is correct
39 Correct 119 ms 17452 KB Output is correct
40 Correct 115 ms 16844 KB Output is correct
41 Correct 89 ms 16080 KB Output is correct
42 Correct 15 ms 9816 KB Output is correct
43 Correct 1 ms 8540 KB Output is correct
44 Correct 2 ms 8540 KB Output is correct
45 Correct 2 ms 8540 KB Output is correct
46 Correct 2 ms 8540 KB Output is correct
47 Correct 1 ms 8540 KB Output is correct
48 Correct 1 ms 8540 KB Output is correct
49 Correct 2 ms 8540 KB Output is correct
50 Correct 2 ms 8540 KB Output is correct
51 Correct 2 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 1 ms 8536 KB Output is correct
54 Correct 1 ms 8792 KB Output is correct
55 Correct 1 ms 8540 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 148 ms 13776 KB Output is correct
58 Correct 134 ms 13792 KB Output is correct
59 Correct 138 ms 13776 KB Output is correct
60 Correct 135 ms 13480 KB Output is correct
61 Correct 137 ms 13520 KB Output is correct
62 Correct 134 ms 13384 KB Output is correct
63 Correct 144 ms 13524 KB Output is correct
64 Correct 135 ms 13628 KB Output is correct
65 Correct 141 ms 13640 KB Output is correct
66 Correct 184 ms 13632 KB Output is correct
67 Correct 156 ms 13796 KB Output is correct
68 Correct 139 ms 13772 KB Output is correct
69 Correct 141 ms 13348 KB Output is correct
70 Correct 140 ms 13520 KB Output is correct
71 Correct 1 ms 8536 KB Output is correct
72 Correct 4 ms 8796 KB Output is correct
73 Correct 4 ms 8796 KB Output is correct
74 Correct 5 ms 8648 KB Output is correct
75 Correct 5 ms 8796 KB Output is correct
76 Correct 4 ms 8796 KB Output is correct
77 Correct 5 ms 8796 KB Output is correct
78 Correct 5 ms 8792 KB Output is correct
79 Correct 5 ms 8796 KB Output is correct
80 Correct 150 ms 13552 KB Output is correct
81 Correct 159 ms 13640 KB Output is correct
82 Correct 151 ms 13520 KB Output is correct
83 Correct 156 ms 13780 KB Output is correct
84 Correct 3 ms 8536 KB Output is correct
85 Correct 3 ms 8540 KB Output is correct
86 Correct 4 ms 8540 KB Output is correct
87 Correct 4 ms 8632 KB Output is correct
88 Correct 4 ms 8540 KB Output is correct
89 Correct 4 ms 8540 KB Output is correct
90 Correct 4 ms 8540 KB Output is correct
91 Correct 4 ms 8796 KB Output is correct
92 Correct 4 ms 8540 KB Output is correct
93 Correct 4 ms 8540 KB Output is correct
94 Correct 2 ms 8536 KB Output is correct
95 Correct 1 ms 8540 KB Output is correct
96 Correct 1 ms 8540 KB Output is correct
97 Correct 2 ms 8536 KB Output is correct
98 Correct 1 ms 8540 KB Output is correct
99 Correct 1 ms 8540 KB Output is correct
100 Correct 1 ms 8540 KB Output is correct
101 Correct 2 ms 8540 KB Output is correct
102 Correct 1 ms 8540 KB Output is correct
103 Correct 1 ms 8540 KB Output is correct
104 Correct 13 ms 9308 KB Output is correct
105 Correct 26 ms 10588 KB Output is correct
106 Correct 2 ms 8540 KB Output is correct
107 Correct 64 ms 12040 KB Output is correct
108 Correct 56 ms 14292 KB Output is correct
109 Correct 2 ms 8540 KB Output is correct
110 Correct 97 ms 14476 KB Output is correct
111 Correct 107 ms 15828 KB Output is correct
112 Correct 2 ms 8540 KB Output is correct
113 Correct 152 ms 22340 KB Output is correct
114 Correct 17 ms 11228 KB Output is correct
115 Incorrect 17 ms 11352 KB Output isn't correct
116 Halted 0 ms 0 KB -