답안 #946888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946888 2024-03-15T07:13:24 Z shenfe1 Amusement Park (JOI17_amusement_park) C++17
63 / 100
214 ms 262144 KB
#include "Joi.h"
 
#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=1e6+15;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
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)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}
 
struct JOIKUN{
  vector<int> g[MAX];
  vector<int> g1[MAX];
  bool use[MAX];
  int d[MAX],root=0;
  int cnt=0;
 
  void dfs(int v){
    use[v]=1;
    for(auto to:g[v]){
      if(!use[to]){
        cnt++;
        d[to]=d[v]+1;
        g1[v].pb(to);
        g1[to].pb(v);
        dfs(to);
      }
    }
  }
 
  int mxD=0;
  int D[MAX];
 
  void dfs1(int v,int p=-1){
    mxD=max(mxD,d[v]+1);
    for(auto to:g1[v]){
      if(to==p)continue;
      d[to]=d[v]+1;
      dfs1(to,v);
    }
  }
 
  void calc(int v,int p=-1){
    D[v]=v;
    for(auto to:g1[v]){
      if(to==p)continue;
      calc(to,v);
      if(d[D[v]]<d[D[to]])D[v]=D[to];
    }
  }
 
  int bit(ll i,int j){
    return (i>>j)&1;
  }
 
  vector<int> top;
 
  void topsort(int v,int p=-1){
    top.pb(v);
    for(auto to:g[v]){
      if(to==p)continue;
      topsort(to,v);
    }
  }
 
  void solve(int N,int M,int A[],int B[],ll X,int T){
    for(int i=0;i<M;i++){
      g[A[i]].pb(B[i]);
      g[B[i]].pb(A[i]);
    }
    dfs(0);
    assert(cnt==N-1);
    for(int i=0;i<N;i++){
      use[i]=0;
      if(d[i]>d[root])root=i;
    }
    d[root]=0;
    dfs1(root);
    calc(root);
    if(mxD>=60){
      for(int i=0;i<N;i++){
        MessageBoard(i,bit(X,d[i]%60));
      }
      return;
    }
    topsort(root);
    for(int i=0;i<sz(top);i++){
      MessageBoard(top[i],bit(X,i%60));
    }
  }
}t;
 
void Joi(int N, int M, int A[], int B[], long long X, int T) {
  t.solve(N,M,A,B,X,T);
}
#include "Ioi.h"
 
#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=1e6+15;
const int B=500;
const int maxB=1000;
const int N=104;
const int block=450;
const ll inf=1e9;  
const int mod=1e9+7;
const int mod1=1e9+9;
const ld eps=1e-9;
 
struct IOICHAN{
 
  ll ans=0;
 
  vector<int> g[MAX];
  vector<int> g1[MAX];
  int use[MAX];
  int d[MAX],root=0;
  int pr[MAX];
  int cnt=0;
 
  void dfs(int v){
    use[v]=1;
    for(auto to:g[v]){
      if(!use[to]){
        d[to]=d[v]+1;
        cnt++;
        g1[v].pb(to);
        g1[to].pb(v);
        dfs(to);
      }
    }
  }
 
  int mxD=0;
  int D[MAX];
  int big[MAX];
 
  void dfs1(int v,int p=-1){
    pr[v]=p;
    mxD=max(mxD,d[v]+1);
    for(auto to:g1[v]){
      if(to==p)continue;
      d[to]=d[v]+1;
      dfs1(to,v);
    }
  }
 
  void calc(int v,int p=-1){
    D[v]=v;
    big[v]=-1;
    for(auto to:g1[v]){
      if(to==p)continue;
      calc(to,v);
      if(d[D[v]]<d[D[to]]){
        D[v]=D[to];
        big[v]=to;
      }
    }
  }
 
  vector<int> top;
 
  void topsort(int v,int p=-1){
    top.pb(v);
    for(auto to:g[v]){
      if(to==p)continue;
      topsort(to,v);
    }
  }
 
 
  ll solve(int N,int M,int A[],int B[],int P,int V,int T){
    for(int i=0;i<M;i++){
      g[A[i]].pb(B[i]);
      g[B[i]].pb(A[i]);
    }
    dfs(0);
    assert(cnt==N-1);
    for(int i=0;i<N;i++){
      use[i]=0;
      if(d[i]>d[root])root=i;
    }
    d[root]=0;
    dfs1(root);
    calc(root);
    // cout<<mxD<<"\n";
    if(mxD+1>=60){
      int cnt=0;
      while(d[P]%60!=0||d[D[P]]-d[P]<59){
        cnt++;
        if(cnt>120||P==-1){assert(0);}
        V=Move(pr[P]);
        P=pr[P];
      }
      ans+=V*(1ll<<0);
      for(int i=1;i<60;i++){
        if(P==-1)assert(0);
        V=Move(big[P]);
        P=big[P];
        ans+=V*(1ll<<i);
      }
      return ans;
    }
    topsort(root);
    while(P!=root){
      V=Move(pr[P]);
      P=pr[P];
    }
    ans+=V*(1ll<<0);
    assert(sz(top)>=60);
    for(int i=1;i<60;i++){
      int L=top[i];
      int cnt=0;
      while(P!=L){
        cnt++;
        if(cnt>60){
          return -1;
        }
        if(pr[L]==P){
          V=Move(L);
          P=L;
        }
        else{
          V=Move(pr[P]);
          P=pr[P];
        }
      }
      ans+=V*(1ll<<i);
    }
    return ans;
  }
}g;
 
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  return g.solve(N,M,A,B,P,V,T);
}

Compilation message

Joi.cpp:5: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    5 | #pragma optimize("Ofast")
      | 
Joi.cpp:6: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    6 | #pragma target("avx2")
      | 

Ioi.cpp:5: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    5 | #pragma optimize("Ofast")
      | 
Ioi.cpp:6: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    6 | #pragma target("avx2")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 103700 KB Output is correct
2 Correct 23 ms 103684 KB Output is correct
3 Correct 24 ms 103696 KB Output is correct
4 Correct 23 ms 103700 KB Output is correct
5 Correct 24 ms 103736 KB Output is correct
6 Correct 22 ms 103692 KB Output is correct
7 Correct 23 ms 103700 KB Output is correct
8 Correct 23 ms 103692 KB Output is correct
9 Correct 23 ms 103712 KB Output is correct
10 Runtime error 195 ms 262144 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 107216 KB Output is correct
2 Correct 43 ms 107356 KB Output is correct
3 Correct 43 ms 107212 KB Output is correct
4 Correct 37 ms 106348 KB Output is correct
5 Correct 41 ms 106764 KB Output is correct
6 Correct 36 ms 106300 KB Output is correct
7 Correct 35 ms 106372 KB Output is correct
8 Correct 35 ms 106280 KB Output is correct
9 Correct 36 ms 106204 KB Output is correct
10 Correct 36 ms 106252 KB Output is correct
11 Correct 33 ms 106296 KB Output is correct
12 Correct 36 ms 105740 KB Output is correct
13 Correct 35 ms 105976 KB Output is correct
14 Correct 35 ms 106280 KB Output is correct
15 Correct 38 ms 106532 KB Output is correct
16 Correct 36 ms 106256 KB Output is correct
17 Correct 35 ms 106304 KB Output is correct
18 Correct 36 ms 106320 KB Output is correct
19 Correct 36 ms 106120 KB Output is correct
20 Correct 32 ms 106208 KB Output is correct
21 Correct 35 ms 106292 KB Output is correct
22 Correct 37 ms 106192 KB Output is correct
23 Correct 39 ms 106308 KB Output is correct
24 Correct 35 ms 106216 KB Output is correct
25 Correct 36 ms 106280 KB Output is correct
26 Correct 36 ms 106552 KB Output is correct
27 Correct 36 ms 106236 KB Output is correct
28 Correct 36 ms 106260 KB Output is correct
29 Correct 34 ms 106204 KB Output is correct
30 Correct 36 ms 106288 KB Output is correct
31 Correct 26 ms 103724 KB Output is correct
32 Correct 24 ms 103772 KB Output is correct
33 Correct 25 ms 103708 KB Output is correct
34 Runtime error 214 ms 262144 KB Execution killed with signal 9
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 103668 KB Output is correct
2 Correct 24 ms 103704 KB Output is correct
3 Correct 23 ms 103916 KB Output is correct
4 Correct 26 ms 104256 KB Output is correct
5 Correct 24 ms 104280 KB Output is correct
6 Correct 26 ms 104288 KB Output is correct
7 Correct 25 ms 104312 KB Output is correct
8 Correct 26 ms 104252 KB Output is correct
9 Correct 33 ms 106908 KB Output is correct
10 Correct 33 ms 106716 KB Output is correct
11 Correct 32 ms 106796 KB Output is correct
12 Correct 23 ms 103704 KB Output is correct
13 Correct 23 ms 103708 KB Output is correct
14 Correct 26 ms 103708 KB Output is correct
15 Correct 24 ms 103696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 107304 KB Output is correct
2 Correct 41 ms 107292 KB Output is correct
3 Correct 41 ms 107504 KB Output is correct
4 Partially correct 36 ms 106300 KB Partially correct
5 Correct 36 ms 106808 KB Output is correct
6 Correct 36 ms 106204 KB Output is correct
7 Correct 36 ms 106416 KB Output is correct
8 Correct 36 ms 106292 KB Output is correct
9 Correct 37 ms 106304 KB Output is correct
10 Correct 34 ms 106280 KB Output is correct
11 Correct 36 ms 106300 KB Output is correct
12 Correct 34 ms 105912 KB Output is correct
13 Partially correct 35 ms 105768 KB Partially correct
14 Partially correct 34 ms 106292 KB Partially correct
15 Partially correct 36 ms 106304 KB Partially correct
16 Partially correct 37 ms 106188 KB Partially correct
17 Correct 39 ms 106280 KB Output is correct
18 Partially correct 36 ms 106280 KB Partially correct
19 Partially correct 36 ms 106300 KB Partially correct
20 Correct 34 ms 106260 KB Output is correct
21 Correct 32 ms 106280 KB Output is correct
22 Correct 34 ms 106336 KB Output is correct
23 Correct 38 ms 106284 KB Output is correct
24 Correct 37 ms 106204 KB Output is correct
25 Correct 36 ms 106276 KB Output is correct
26 Correct 36 ms 106292 KB Output is correct
27 Correct 37 ms 106392 KB Output is correct
28 Correct 36 ms 106248 KB Output is correct
29 Correct 35 ms 106252 KB Output is correct
30 Correct 38 ms 106212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 107336 KB Output is correct
2 Correct 41 ms 107300 KB Output is correct
3 Correct 41 ms 107284 KB Output is correct
4 Incorrect 36 ms 106248 KB Output isn't correct
5 Halted 0 ms 0 KB -