답안 #1077613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077613 2024-08-27T08:21:31 Z vnm06 Amusement Park (JOI17_amusement_park) C++14
82 / 100
24 ms 4452 KB
#include "Joi.h"
#include<bits/stdc++.h>

using namespace std;

long long _x;
int _n, _m;
vector<int> _gr[10005];
int _par[10005], _dpt[10005], _root;
bool _used[10005];

queue<int> _qu;

int _br=0;
void _euler_tour(int v)
{
  MessageBoard(v, bool(_x&((long long)1<<(_br%60))));
  _used[v]=1;
  int _brs=_gr[v].size();
  for(int i=0; i<_brs; i++)
  {
    int nv=_gr[v][i];
    if(_used[nv]) continue;
    _br++;
    _euler_tour(nv);
  }
}

void _find_diam()
{
  _qu.push(0);
  _used[0]=1;
  int lastv;


  while(!_qu.empty())
  {
    lastv=_qu.front();
    _qu.pop();
    int _brs=_gr[lastv].size();
    for(int i=0; i<_brs; i++)
    {
      int nv=_gr[lastv][i];
      if(!_used[nv])
      {
        _used[nv]=1;
        _qu.push(nv);
      }
    }
  }
  for(int i=0; i<_n; i++) _used[i]=0;
  _used[lastv]=1;
  _par[lastv]=lastv;
  _root=lastv;
  _qu.push(lastv);

  while(!_qu.empty())
  {
    lastv=_qu.front();
    _qu.pop();
    int _brs=_gr[lastv].size();
    for(int i=0; i<_brs; i++)
    {
      int nv=_gr[lastv][i];
      if(!_used[nv])
      {
        _used[nv]=1;
        _par[nv]=lastv;
        _dpt[nv]=_dpt[lastv]+1;
        _qu.push(nv);
      }
    }
  }

  if(_dpt[lastv]>=59)
  {
    for(int i=0; i<_n; i++) {MessageBoard(i, bool(_x&((long long)1<<(_dpt[i]%60)))); /**cout<<((long long)1<<(_dpt[i]%60))<<endl;*/}
    return;
  }

  int lng=_dpt[lastv]+1, nr=lastv;
  for(int i=1; i<lng/2; i++) nr=_par[nr];
  for(int i=0; i<_n; i++) _used[i]=0;
  _euler_tour(nr);

}

void Joi(int N, int M, int A[], int B[], long long X, int T) 
{
  _n=N;
  _m=M;
  _x=X;
  for(int i=0; i<M; i++)
  {
    _gr[A[i]].push_back(B[i]);
    _gr[B[i]].push_back(A[i]);
  }
  _find_diam();
}
#include "Ioi.h"
#include<bits/stdc++.h>

using namespace std;

long long x=0;
int n, m, p;
vector<int> gr[10005];
int par[10005], dpt[10005], root;
bool used[10005];
long long tval[10005];
long long tpos[10005];
int destn[10005];

queue<int> qu;

int cnt=0;
int _Move(int t)
{
  cnt++;
  ///if(cnt>500) assert(false);
  return Move(t);
}

int br=0;
void euler_tour(int v)
{
  tpos[v]=br%60;
  used[v]=1;
  int brs=gr[v].size();
  for(int i=0; i<brs; i++)
  {
    int nv=gr[v][i];
    if(used[nv]) continue;
    br++;
    euler_tour(nv);
  }
}

bool prikl=0;

void euler_tour2(int v)
{
  x|=(tval[v]<<tpos[v]);
  if(br>=59) return;
  used[v]=1;
  int brs=gr[v].size();
  for(int i=0; i<brs; i++)
  {
    int nv=gr[v][i];
    if(used[nv]) continue;
    br++;
    tval[nv]=_Move(nv);
    euler_tour2(nv);
    if(br>=59) return;
  }
  _Move(par[v]);
}

long long find_diam()
{
  qu.push(0);
  used[0]=1;
  int lastv;
  while(!qu.empty())
  {
    lastv=qu.front();
    qu.pop();
    int brs=gr[lastv].size();
    for(int i=0; i<brs; i++)
    {
      int nv=gr[lastv][i];
      if(!used[nv])
      {
        used[nv]=1;
        qu.push(nv);
      }
    }
  }
  for(int i=0; i<n; i++) used[i]=0;
  used[lastv]=1;
  par[lastv]=lastv;
  root=lastv;
  qu.push(lastv);

  while(!qu.empty())
  {
    lastv=qu.front();
    qu.pop();
    int brs=gr[lastv].size();
    for(int i=0; i<brs; i++)
    {
      int nv=gr[lastv][i];
      if(!used[nv])
      {
        used[nv]=1;
        par[nv]=lastv;
        dpt[nv]=dpt[lastv]+1;
        qu.push(nv);
      }
    }
  }

  if(dpt[lastv]>=59)
  {
    for(int i=0; i<n; i++) tpos[i]=dpt[i]%60;
    for(int i=0; i<60; i++)
    {
      x|=(tval[p]<<tpos[p]);
      if(p==par[p]) break;
      tval[par[p]]=_Move(par[p]);
      p=par[p];
    }
    destn[lastv]=-1;
    //cout<<'d'<<lastv<<endl;
    while(lastv!=par[lastv])
    {
      destn[par[lastv]]=lastv;
      //cout<<lastv<<endl;
      lastv=par[lastv];
    }
    for(int i=0; i<60; i++)
    {
      //cout<<x<<endl;
      x|=(tval[p]<<tpos[p]);
      if(destn[p]==-1) break;
      tval[destn[p]]=_Move(destn[p]);
      p=destn[p];
    }
    return x;
  }
  /////cout<<dpt[lastv]<<endl;

  int lng=dpt[lastv]+1, nr=lastv;
  for(int i=1; i<lng/2; i++) nr=par[nr];
  

  par[nr]=nr;

  for(int i=0; i<n; i++) used[i]=0;
  used[nr]=1;
  qu.push(nr);

  while(!qu.empty())
  {
    lastv=qu.front();
    qu.pop();
    int brs=gr[lastv].size();
    for(int i=0; i<brs; i++)
    {
      int nv=gr[lastv][i];
      if(!used[nv])
      {
        used[nv]=1;
        par[nv]=lastv;
        qu.push(nv);
      }
    }
  }




  for(int i=0; i<n; i++) used[i]=0;
  euler_tour(nr);

  int tot=0;
  while(p!=par[p])
  {
    tot++;
    if(tot>500) assert(false);
      x|=(tval[p]<<tpos[p]);
      tval[par[p]]=_Move(par[p]);
      p=par[p];
  }
  br=0;
  for(int i=0; i<n; i++) used[i]=0;
  euler_tour2(p);
  return x;
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) 
{
  n=N;
  m=M;
  p=P;
  tval[P]=V;
  for(int i=0; i<M; i++)
  {
    gr[A[i]].push_back(B[i]);
    gr[B[i]].push_back(A[i]);
  }
  return find_diam();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1296 KB Output is correct
2 Correct 0 ms 1308 KB Output is correct
3 Correct 1 ms 1304 KB Output is correct
4 Correct 0 ms 1296 KB Output is correct
5 Correct 0 ms 1312 KB Output is correct
6 Correct 2 ms 1296 KB Output is correct
7 Correct 1 ms 1312 KB Output is correct
8 Correct 1 ms 1296 KB Output is correct
9 Correct 2 ms 1304 KB Output is correct
10 Correct 1 ms 1308 KB Output is correct
11 Correct 3 ms 1604 KB Output is correct
12 Correct 2 ms 1292 KB Output is correct
13 Correct 2 ms 1312 KB Output is correct
14 Correct 2 ms 1304 KB Output is correct
15 Correct 1 ms 1312 KB Output is correct
16 Correct 0 ms 1304 KB Output is correct
17 Correct 1 ms 1304 KB Output is correct
18 Correct 2 ms 1352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4196 KB Output is correct
2 Correct 24 ms 4128 KB Output is correct
3 Correct 19 ms 4444 KB Output is correct
4 Correct 11 ms 3028 KB Output is correct
5 Correct 9 ms 3128 KB Output is correct
6 Correct 9 ms 3040 KB Output is correct
7 Correct 9 ms 3036 KB Output is correct
8 Correct 11 ms 3136 KB Output is correct
9 Correct 9 ms 3076 KB Output is correct
10 Correct 9 ms 3028 KB Output is correct
11 Correct 9 ms 3044 KB Output is correct
12 Correct 9 ms 2992 KB Output is correct
13 Correct 10 ms 3016 KB Output is correct
14 Correct 9 ms 3024 KB Output is correct
15 Correct 10 ms 3028 KB Output is correct
16 Correct 9 ms 3068 KB Output is correct
17 Correct 13 ms 3044 KB Output is correct
18 Correct 11 ms 3032 KB Output is correct
19 Correct 14 ms 3032 KB Output is correct
20 Correct 10 ms 3032 KB Output is correct
21 Correct 9 ms 3040 KB Output is correct
22 Correct 9 ms 3032 KB Output is correct
23 Correct 9 ms 3032 KB Output is correct
24 Correct 9 ms 3032 KB Output is correct
25 Correct 8 ms 3028 KB Output is correct
26 Correct 11 ms 3036 KB Output is correct
27 Correct 13 ms 3028 KB Output is correct
28 Correct 9 ms 3036 KB Output is correct
29 Correct 8 ms 3012 KB Output is correct
30 Correct 10 ms 3024 KB Output is correct
31 Correct 2 ms 1304 KB Output is correct
32 Correct 2 ms 1296 KB Output is correct
33 Correct 2 ms 1304 KB Output is correct
34 Correct 2 ms 1304 KB Output is correct
35 Correct 1 ms 1308 KB Output is correct
36 Correct 1 ms 1296 KB Output is correct
37 Correct 1 ms 1308 KB Output is correct
38 Correct 1 ms 1304 KB Output is correct
39 Correct 1 ms 1296 KB Output is correct
40 Correct 0 ms 1308 KB Output is correct
41 Correct 0 ms 1308 KB Output is correct
42 Correct 1 ms 1308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1308 KB Output is correct
2 Correct 1 ms 1304 KB Output is correct
3 Correct 2 ms 1308 KB Output is correct
4 Correct 2 ms 1336 KB Output is correct
5 Correct 2 ms 1324 KB Output is correct
6 Correct 2 ms 1336 KB Output is correct
7 Correct 2 ms 1336 KB Output is correct
8 Correct 2 ms 1324 KB Output is correct
9 Correct 7 ms 3036 KB Output is correct
10 Correct 11 ms 3032 KB Output is correct
11 Correct 9 ms 3032 KB Output is correct
12 Correct 1 ms 1308 KB Output is correct
13 Correct 1 ms 1296 KB Output is correct
14 Correct 0 ms 1300 KB Output is correct
15 Correct 1 ms 1308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 4448 KB Output is correct
2 Correct 23 ms 4452 KB Output is correct
3 Correct 23 ms 4320 KB Output is correct
4 Correct 15 ms 3032 KB Output is correct
5 Correct 9 ms 3040 KB Output is correct
6 Correct 9 ms 3024 KB Output is correct
7 Correct 12 ms 3032 KB Output is correct
8 Correct 9 ms 2960 KB Output is correct
9 Correct 9 ms 3032 KB Output is correct
10 Correct 10 ms 3028 KB Output is correct
11 Correct 8 ms 3040 KB Output is correct
12 Correct 11 ms 3024 KB Output is correct
13 Correct 8 ms 3276 KB Output is correct
14 Correct 12 ms 3012 KB Output is correct
15 Correct 12 ms 3036 KB Output is correct
16 Correct 11 ms 3032 KB Output is correct
17 Correct 10 ms 3032 KB Output is correct
18 Correct 9 ms 3040 KB Output is correct
19 Partially correct 11 ms 3032 KB Partially correct
20 Correct 7 ms 2896 KB Output is correct
21 Correct 8 ms 3128 KB Output is correct
22 Correct 10 ms 3124 KB Output is correct
23 Correct 11 ms 3124 KB Output is correct
24 Correct 9 ms 3124 KB Output is correct
25 Correct 12 ms 3124 KB Output is correct
26 Correct 9 ms 3136 KB Output is correct
27 Correct 9 ms 3136 KB Output is correct
28 Correct 12 ms 3128 KB Output is correct
29 Correct 8 ms 3112 KB Output is correct
30 Correct 9 ms 3112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4356 KB Output is correct
2 Correct 22 ms 4448 KB Output is correct
3 Correct 17 ms 4368 KB Output is correct
4 Correct 9 ms 3360 KB Output is correct
5 Correct 9 ms 3124 KB Output is correct
6 Correct 11 ms 3140 KB Output is correct
7 Correct 11 ms 3108 KB Output is correct
8 Correct 13 ms 3128 KB Output is correct
9 Correct 9 ms 3128 KB Output is correct
10 Correct 9 ms 3388 KB Output is correct
11 Correct 9 ms 3396 KB Output is correct
12 Correct 10 ms 2944 KB Output is correct
13 Correct 13 ms 3096 KB Output is correct
14 Correct 9 ms 3212 KB Output is correct
15 Correct 10 ms 3144 KB Output is correct
16 Incorrect 9 ms 3024 KB Output isn't correct
17 Halted 0 ms 0 KB -