답안 #1104669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104669 2024-10-24T08:31:01 Z sweed 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
0 / 100
6 ms 33528 KB
#include "garden.h"
#include "gardenlib.h"
#define pb emplace_back
#include<bits/stdc++.h>
using namespace std;
int up[300005][1000];
vector<int>g[300005];
vector<int>g2[600005];
int jp=0;
void dfs(int u,int pr)
{
  if(pr!=-1 and up[pr][0]!=-1) return;
  if(pr!=-1) up[pr][0] = u;
  for(auto v:g2[u])
  {
    if(v!=pr) dfs(v,u);
  }
}

void setup(int n)
{
  jp=log2(n)+1;
  for(int i=0;i<2*n;i++) up[i][0]=-1;
  
  for(int i=0;i<2*n;i++) 
  {
    if(up[i][0]!=-1) continue;
    dfs(i,-1);
  }
  // for(int i=0;i<2*n;i++) cout << up[i][0] << endl;
  for(int i=1;i<=jp;i++)
  {
    for(int j=0;j<2*n;j++)
    {
      up[j][i] = up[up[j][i-1]][i-1];
    }
  }
}
int jump(int u,int x)
{
  for(int i=jp-1;i>=0;i--)
  {
    if((x&(1<<i))==1<<i)
    {
      u=up[u][i];
    }
  }
  return u;
}
 
 
void count_routes(int n, int m, int p, int R[][2], int Q, int G[])
{
  
  for(int i=0;i<m;i++)
  {
    if(g[R[i][0]].size()<=2) g[R[i][0]].pb(R[i][1]);
    if(g[R[i][1]].size()<=2) g[R[i][1]].pb(R[i][0]);
  }
  for(int i=0;i<n;i++)
  {
    int v = g[i][0];
    if(i==g[v][0] and g[v].size()!=1) g2[i].pb(v+n);
    else  g2[i].pb(v);
    int vv;
    if(g[i].size()!=1) vv = g[i][1];
    else vv = g[i][0];
 
    if(i==g[vv][0]) g2[i+n].pb(vv+n);
    else  g2[i+n].pb(vv);
  }
  // for(int i=0;i<2*n;i++)
  // {
  //   cout << i << " " << g2[i][0] << endl;
  // }

  setup(n);
  for(int k=0;k<Q;k++)
  {
    int d = G[k];
    int ans=0;
    for(int i=0;i<n;i++)
    {
      int u=i;
      u = jump(u,d);
      // for(int j=0;j<d;j++)
      // {
      //   u = g2[u][0];
      // }
      if(u==p or u==p+n) ans++;
    }
    // for(int i=0;i<n;i++)
    // {
    //   for(int j=0;j<n;j++)
    //   {
        
    //     int u=i;
    //     for(int k=0;k<j;k++)
    //     {
    //       u = g2[u][0];
    //     }
    //     cout << jump(i,j) << " " << u << endl;
    //   }
    // }
    answer(ans);
  }
  
 
  // for(int i=0; i<Q; i++)
  // answer(n);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31312 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Correct 6 ms 33528 KB Output is correct
4 Correct 4 ms 25168 KB Output is correct
5 Incorrect 5 ms 25024 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31312 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Correct 6 ms 33528 KB Output is correct
4 Correct 4 ms 25168 KB Output is correct
5 Incorrect 5 ms 25024 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31312 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Correct 6 ms 33528 KB Output is correct
4 Correct 4 ms 25168 KB Output is correct
5 Incorrect 5 ms 25024 KB Output isn't correct
6 Halted 0 ms 0 KB -