답안 #940157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940157 2024-03-07T06:10:29 Z vjudge1 꿈 (IOI13_dreaming) C++17
0 / 100
133 ms 17380 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 int B=2e5;
const int N=104;
const int block=450;
const int maxB=MAX/B+10;
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 mx=inf;
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];

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){
  if(add[v]==0)return;
  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]);
}

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

int solve(vector<int> ver){
  timer=0;
  mem(rev,0);
  dfs(ver[0]);
  // for(int i=1;i<=n;i++)cout<<rev[i]<<" ";
  // cout<<"\n";
  build(1,1,n);
  
  return calc(ver[0]);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  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 ans=L;
  dfs1(1);
  ans+=solve(vec);
  vec.clear();
  for(int i=1;i<=N;i++){
    if(!use[i]){
      dfs1(i);
      // cout<<solve(vec)<<"\n";
      ans+=solve(vec);
      break;
    }
  }
  return 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 Incorrect 133 ms 17380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 133 ms 17380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 10588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 133 ms 17380 KB Output isn't correct
2 Halted 0 ms 0 KB -