답안 #940242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940242 2024-03-07T06:56:34 Z shenfe1 꿈 (IOI13_dreaming) C++17
47 / 100
180 ms 22228 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();
    }
  }
  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")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 17804 KB Output is correct
2 Correct 121 ms 17412 KB Output is correct
3 Correct 103 ms 16288 KB Output is correct
4 Correct 16 ms 9820 KB Output is correct
5 Correct 12 ms 9308 KB Output is correct
6 Correct 27 ms 10584 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 50 ms 12140 KB Output is correct
9 Correct 53 ms 14560 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 109 ms 14760 KB Output is correct
12 Correct 106 ms 15936 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8628 KB Output is correct
5 Correct 2 ms 8548 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 2 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 8536 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 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 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8640 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 17804 KB Output is correct
2 Correct 121 ms 17412 KB Output is correct
3 Correct 103 ms 16288 KB Output is correct
4 Correct 16 ms 9820 KB Output is correct
5 Correct 12 ms 9308 KB Output is correct
6 Correct 27 ms 10584 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 50 ms 12140 KB Output is correct
9 Correct 53 ms 14560 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 109 ms 14760 KB Output is correct
12 Correct 106 ms 15936 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 1 ms 8628 KB Output is correct
18 Correct 2 ms 8548 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 2 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 8536 KB Output is correct
27 Correct 2 ms 8792 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 1 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 1 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8640 KB Output is correct
38 Correct 2 ms 8792 KB Output is correct
39 Correct 128 ms 17576 KB Output is correct
40 Correct 119 ms 17268 KB Output is correct
41 Correct 89 ms 16340 KB Output is correct
42 Correct 16 ms 9820 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 2 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 4 ms 8536 KB Output is correct
51 Correct 1 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 2 ms 8536 KB Output is correct
54 Correct 1 ms 8628 KB Output is correct
55 Correct 2 ms 8536 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 158 ms 14096 KB Output is correct
58 Correct 142 ms 13772 KB Output is correct
59 Correct 157 ms 13984 KB Output is correct
60 Correct 147 ms 13852 KB Output is correct
61 Correct 141 ms 14028 KB Output is correct
62 Correct 152 ms 13908 KB Output is correct
63 Correct 139 ms 13912 KB Output is correct
64 Correct 180 ms 14036 KB Output is correct
65 Correct 154 ms 13928 KB Output is correct
66 Correct 142 ms 14032 KB Output is correct
67 Correct 156 ms 14032 KB Output is correct
68 Correct 154 ms 13928 KB Output is correct
69 Correct 141 ms 13868 KB Output is correct
70 Correct 150 ms 13832 KB Output is correct
71 Correct 2 ms 8536 KB Output is correct
72 Correct 4 ms 9048 KB Output is correct
73 Correct 4 ms 8816 KB Output is correct
74 Correct 5 ms 8796 KB Output is correct
75 Correct 4 ms 8796 KB Output is correct
76 Correct 5 ms 8796 KB Output is correct
77 Correct 5 ms 8804 KB Output is correct
78 Correct 5 ms 8796 KB Output is correct
79 Correct 5 ms 8808 KB Output is correct
80 Correct 157 ms 14172 KB Output is correct
81 Correct 164 ms 14284 KB Output is correct
82 Correct 150 ms 13784 KB Output is correct
83 Correct 141 ms 13864 KB Output is correct
84 Correct 4 ms 8536 KB Output is correct
85 Correct 4 ms 8540 KB Output is correct
86 Correct 5 ms 8540 KB Output is correct
87 Correct 4 ms 8536 KB Output is correct
88 Correct 4 ms 8540 KB Output is correct
89 Correct 4 ms 8536 KB Output is correct
90 Correct 5 ms 8536 KB Output is correct
91 Correct 5 ms 8648 KB Output is correct
92 Correct 6 ms 8540 KB Output is correct
93 Correct 4 ms 8540 KB Output is correct
94 Correct 1 ms 8540 KB Output is correct
95 Correct 2 ms 8588 KB Output is correct
96 Correct 2 ms 8656 KB Output is correct
97 Correct 2 ms 8536 KB Output is correct
98 Correct 2 ms 8540 KB Output is correct
99 Correct 2 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 2 ms 8540 KB Output is correct
103 Correct 2 ms 8540 KB Output is correct
104 Correct 14 ms 9308 KB Output is correct
105 Correct 27 ms 10568 KB Output is correct
106 Correct 2 ms 8540 KB Output is correct
107 Correct 49 ms 12024 KB Output is correct
108 Correct 56 ms 14368 KB Output is correct
109 Correct 2 ms 8540 KB Output is correct
110 Correct 123 ms 14716 KB Output is correct
111 Correct 108 ms 15948 KB Output is correct
112 Correct 2 ms 8536 KB Output is correct
113 Correct 129 ms 22228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 13136 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 2 ms 8536 KB Output is correct
4 Correct 1 ms 8628 KB Output is correct
5 Correct 2 ms 8548 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 2 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 8536 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 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 2 ms 8540 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8640 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Runtime error 6 ms 12892 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 118 ms 17804 KB Output is correct
2 Correct 121 ms 17412 KB Output is correct
3 Correct 103 ms 16288 KB Output is correct
4 Correct 16 ms 9820 KB Output is correct
5 Correct 12 ms 9308 KB Output is correct
6 Correct 27 ms 10584 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 50 ms 12140 KB Output is correct
9 Correct 53 ms 14560 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 109 ms 14760 KB Output is correct
12 Correct 106 ms 15936 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 2 ms 8536 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8536 KB Output is correct
17 Correct 1 ms 8628 KB Output is correct
18 Correct 2 ms 8548 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 2 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 8536 KB Output is correct
27 Correct 2 ms 8792 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 2 ms 8540 KB Output is correct
32 Correct 1 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 1 ms 8540 KB Output is correct
36 Correct 1 ms 8540 KB Output is correct
37 Correct 1 ms 8640 KB Output is correct
38 Correct 2 ms 8792 KB Output is correct
39 Correct 128 ms 17576 KB Output is correct
40 Correct 119 ms 17268 KB Output is correct
41 Correct 89 ms 16340 KB Output is correct
42 Correct 16 ms 9820 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 2 ms 8540 KB Output is correct
48 Correct 2 ms 8540 KB Output is correct
49 Correct 1 ms 8540 KB Output is correct
50 Correct 4 ms 8536 KB Output is correct
51 Correct 1 ms 8540 KB Output is correct
52 Correct 2 ms 8540 KB Output is correct
53 Correct 2 ms 8536 KB Output is correct
54 Correct 1 ms 8628 KB Output is correct
55 Correct 2 ms 8536 KB Output is correct
56 Correct 1 ms 8540 KB Output is correct
57 Correct 158 ms 14096 KB Output is correct
58 Correct 142 ms 13772 KB Output is correct
59 Correct 157 ms 13984 KB Output is correct
60 Correct 147 ms 13852 KB Output is correct
61 Correct 141 ms 14028 KB Output is correct
62 Correct 152 ms 13908 KB Output is correct
63 Correct 139 ms 13912 KB Output is correct
64 Correct 180 ms 14036 KB Output is correct
65 Correct 154 ms 13928 KB Output is correct
66 Correct 142 ms 14032 KB Output is correct
67 Correct 156 ms 14032 KB Output is correct
68 Correct 154 ms 13928 KB Output is correct
69 Correct 141 ms 13868 KB Output is correct
70 Correct 150 ms 13832 KB Output is correct
71 Correct 2 ms 8536 KB Output is correct
72 Correct 4 ms 9048 KB Output is correct
73 Correct 4 ms 8816 KB Output is correct
74 Correct 5 ms 8796 KB Output is correct
75 Correct 4 ms 8796 KB Output is correct
76 Correct 5 ms 8796 KB Output is correct
77 Correct 5 ms 8804 KB Output is correct
78 Correct 5 ms 8796 KB Output is correct
79 Correct 5 ms 8808 KB Output is correct
80 Correct 157 ms 14172 KB Output is correct
81 Correct 164 ms 14284 KB Output is correct
82 Correct 150 ms 13784 KB Output is correct
83 Correct 141 ms 13864 KB Output is correct
84 Correct 4 ms 8536 KB Output is correct
85 Correct 4 ms 8540 KB Output is correct
86 Correct 5 ms 8540 KB Output is correct
87 Correct 4 ms 8536 KB Output is correct
88 Correct 4 ms 8540 KB Output is correct
89 Correct 4 ms 8536 KB Output is correct
90 Correct 5 ms 8536 KB Output is correct
91 Correct 5 ms 8648 KB Output is correct
92 Correct 6 ms 8540 KB Output is correct
93 Correct 4 ms 8540 KB Output is correct
94 Correct 1 ms 8540 KB Output is correct
95 Correct 2 ms 8588 KB Output is correct
96 Correct 2 ms 8656 KB Output is correct
97 Correct 2 ms 8536 KB Output is correct
98 Correct 2 ms 8540 KB Output is correct
99 Correct 2 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 2 ms 8540 KB Output is correct
103 Correct 2 ms 8540 KB Output is correct
104 Correct 14 ms 9308 KB Output is correct
105 Correct 27 ms 10568 KB Output is correct
106 Correct 2 ms 8540 KB Output is correct
107 Correct 49 ms 12024 KB Output is correct
108 Correct 56 ms 14368 KB Output is correct
109 Correct 2 ms 8540 KB Output is correct
110 Correct 123 ms 14716 KB Output is correct
111 Correct 108 ms 15948 KB Output is correct
112 Correct 2 ms 8536 KB Output is correct
113 Correct 129 ms 22228 KB Output is correct
114 Runtime error 12 ms 13136 KB Execution killed with signal 6
115 Halted 0 ms 0 KB -