답안 #929369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
929369 2024-02-18T05:09:48 Z huutuan Amusement Park (JOI17_amusement_park) C++14
100 / 100
20 ms 5744 KB
#include "Joi.h"

#include<bits/stdc++.h>
using namespace std;

namespace joi{
   #define int long long
   const int N=1e4+10, M=2e4+10;
   int n;
   int m;
   vector<int> g[N];
   pair<int, int> edge[M];
   int dep[N], par[N];
   void dfs_dep(int u){
      for (int v:g[u]) if (dep[v]==-1){
         dep[v]=dep[u]+1;
         par[v]=u;
         dfs_dep(v);
      }
   }
   int vis[N];
   vector<int> chosen;
   vector<int> diameter;
   void dfs_choose(int u){
      if ((int)chosen.size()==60) return;
      for (int v:g[u]) if (!vis[v]){
         if ((int)chosen.size()==60) return;
         vis[v]=1;
         chosen.push_back(v);
         dfs_choose(v);
      }
   }
   int ans[N];
   void solve(int x){
      memset(dep, -1, sizeof dep);
      dep[0]=0; par[0]=-1; dfs_dep(0);
      int u=max_element(dep, dep+n)-dep;
      memset(dep, -1, sizeof dep);
      dep[u]=0; par[u]=-1; dfs_dep(u);
      int max_dep=*max_element(dep, dep+n);
      if (max_dep>=60){
         for (int i=0; i<n; ++i) MessageBoard(i, x>>(dep[i]%60)&1);
      }else{
         int v=max_element(dep, dep+n)-dep;
         while (v!=u) chosen.push_back(v), v=par[v];
         chosen.push_back(u);
         reverse(chosen.begin(), chosen.end());
         diameter=chosen;
         for (int i:diameter) vis[i]=1;
         for (int i:diameter) dfs_choose(i);
         for (int i=0; i<60; ++i) ans[chosen[i]]=x>>i&1;
         for (int i=0; i<n; ++i) MessageBoard(i, ans[i]);
      }
   }
   #undef int
}

void Joi(int N, int M, int A[], int B[], long long X, int T) {
   joi::n=N;
   joi::m=M;
   for (int i=0; i<M; ++i){
      joi::g[A[i]].push_back(B[i]);
      joi::g[B[i]].push_back(A[i]);
   }
   joi::solve(X);
}
#include "Ioi.h"

#include<bits/stdc++.h>
using namespace std;

namespace ioi{
   #define int long long
   const int N=1e4+10, M=2e4+10;
   int n;
   int m;
   vector<int> g[N];
   pair<int, int> edge[M];
   int dep[N], par[N];
   void dfs_dep(int u){
      for (int v:g[u]) if (dep[v]==-1){
         dep[v]=dep[u]+1;
         par[v]=u;
         dfs_dep(v);
      }
   }
   int vis[N];
   vector<int> chosen;
   vector<int> diameter;
   vector<int> gg[N];
   void dfs_choose(int u){
      if ((int)chosen.size()==60) return;
      for (int v:g[u]) if (!vis[v]){
         if ((int)chosen.size()==60) return;
         vis[v]=1;
         gg[u].push_back(v);
         chosen.push_back(v);
         dfs_choose(v);
      }
   }
   int ans[N];
   void dfs(int u){
      if (find(diameter.begin(), diameter.end(), u)==diameter.end()){
         for (int v:gg[u]){
            if (find(chosen.begin(), chosen.end(), v)==chosen.end()) continue;
            if (find(diameter.begin(), diameter.end(), v)==diameter.end()){
               ans[v]=Move(v);
               dfs(v);
               Move(u);
            }
         }
         return;
      }
      for (int v:gg[u]) if (v!=gg[u][0]){
         if (find(chosen.begin(), chosen.end(), v)==chosen.end()) continue;
         if (find(diameter.begin(), diameter.end(), v)==diameter.end()){
            ans[v]=Move(v);
            dfs(v);
            Move(u);
         }
      }
      if (gg[u].size()){
         int v=gg[u][0];
         ans[v]=Move(v);
         return dfs(v);
      }
   }
   int solve(int x, int y){
      ans[x]=y;
      memset(dep, -1, sizeof dep);
      dep[0]=0; par[0]=-1; dfs_dep(0);
      int u=max_element(dep, dep+n)-dep;
      memset(dep, -1, sizeof dep);
      dep[u]=0; par[u]=-1; dfs_dep(u);
      int max_dep=*max_element(dep, dep+n);
      if (max_dep>=60){
         if (dep[x]>=59){
            vector<int> path;
            path.push_back(x);
            while ((int)path.size()!=60){
               x=par[x];
               ans[x]=Move(x);
               path.push_back(x);
            }
            int res=0;
            for (int i:path) res|=ans[i]<<(dep[i]%60);
            return res;
         }
         while (x!=u) x=par[x], ans[x]=Move(x);
         int v=max_element(dep, dep+n)-dep;
         vector<int> path;
         while (v!=u) path.push_back(v), v=par[v];
         path.push_back(u);
         reverse(path.begin(), path.end());
         path.resize(60);
         for (int i=1; i<60; ++i) ans[path[i]]=Move(path[i]);
         int res=0;
         for (int i:path) res|=ans[i]<<(dep[i]%60);
         return res;
      }else{
         int v=max_element(dep, dep+n)-dep;
         while (v!=u) chosen.push_back(v), v=par[v];
         chosen.push_back(u);
         reverse(chosen.begin(), chosen.end());
         diameter=chosen;
         for (int i:diameter) vis[i]=1;
         for (int i=0; i<(int)diameter.size()-1; ++i) gg[diameter[i]].push_back(diameter[i+1]);
         for (int i:diameter) dfs_choose(i);
         while (x!=u) x=par[x], ans[x]=Move(x);
         dfs(x);
         int res=0;
         for (int i=0; i<60; ++i) res|=ans[chosen[i]]<<i;
         return res;
      }
      return -1;
   }
   #undef int
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
   ioi::n=N;
   ioi::m=M;
   for (int i=0; i<M; ++i){
      ioi::g[A[i]].push_back(B[i]);
      ioi::g[B[i]].push_back(A[i]);
   }
   return ioi::solve(P, V);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1568 KB Output is correct
2 Correct 2 ms 1552 KB Output is correct
3 Correct 2 ms 1564 KB Output is correct
4 Correct 2 ms 1552 KB Output is correct
5 Correct 1 ms 1636 KB Output is correct
6 Correct 2 ms 1556 KB Output is correct
7 Correct 2 ms 1564 KB Output is correct
8 Correct 2 ms 1572 KB Output is correct
9 Correct 2 ms 1768 KB Output is correct
10 Correct 2 ms 1556 KB Output is correct
11 Correct 4 ms 2140 KB Output is correct
12 Correct 2 ms 1556 KB Output is correct
13 Correct 3 ms 1988 KB Output is correct
14 Correct 2 ms 1644 KB Output is correct
15 Correct 2 ms 1656 KB Output is correct
16 Correct 2 ms 1564 KB Output is correct
17 Correct 2 ms 1560 KB Output is correct
18 Correct 2 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5456 KB Output is correct
2 Correct 19 ms 5596 KB Output is correct
3 Correct 19 ms 5744 KB Output is correct
4 Correct 10 ms 3640 KB Output is correct
5 Correct 11 ms 4416 KB Output is correct
6 Correct 11 ms 4152 KB Output is correct
7 Correct 11 ms 4160 KB Output is correct
8 Correct 11 ms 4324 KB Output is correct
9 Correct 12 ms 4164 KB Output is correct
10 Correct 10 ms 3912 KB Output is correct
11 Correct 10 ms 3880 KB Output is correct
12 Correct 10 ms 3608 KB Output is correct
13 Correct 11 ms 3620 KB Output is correct
14 Correct 10 ms 3884 KB Output is correct
15 Correct 10 ms 3648 KB Output is correct
16 Correct 11 ms 3640 KB Output is correct
17 Correct 12 ms 3644 KB Output is correct
18 Correct 11 ms 3640 KB Output is correct
19 Correct 11 ms 3888 KB Output is correct
20 Correct 10 ms 4132 KB Output is correct
21 Correct 9 ms 4152 KB Output is correct
22 Correct 13 ms 4048 KB Output is correct
23 Correct 12 ms 4224 KB Output is correct
24 Correct 12 ms 4156 KB Output is correct
25 Correct 11 ms 4196 KB Output is correct
26 Correct 14 ms 4156 KB Output is correct
27 Correct 11 ms 4152 KB Output is correct
28 Correct 11 ms 4416 KB Output is correct
29 Correct 11 ms 4132 KB Output is correct
30 Correct 10 ms 4116 KB Output is correct
31 Correct 2 ms 1556 KB Output is correct
32 Correct 2 ms 1560 KB Output is correct
33 Correct 2 ms 1728 KB Output is correct
34 Correct 2 ms 1568 KB Output is correct
35 Correct 1 ms 1568 KB Output is correct
36 Correct 2 ms 1552 KB Output is correct
37 Correct 1 ms 1552 KB Output is correct
38 Correct 2 ms 1556 KB Output is correct
39 Correct 0 ms 1568 KB Output is correct
40 Correct 1 ms 1556 KB Output is correct
41 Correct 1 ms 1568 KB Output is correct
42 Correct 2 ms 1556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1624 KB Output is correct
2 Correct 1 ms 1556 KB Output is correct
3 Correct 1 ms 1568 KB Output is correct
4 Correct 2 ms 2112 KB Output is correct
5 Correct 3 ms 2216 KB Output is correct
6 Correct 2 ms 2116 KB Output is correct
7 Correct 3 ms 2112 KB Output is correct
8 Correct 3 ms 2208 KB Output is correct
9 Correct 8 ms 4160 KB Output is correct
10 Correct 12 ms 4208 KB Output is correct
11 Correct 10 ms 4664 KB Output is correct
12 Correct 1 ms 1556 KB Output is correct
13 Correct 2 ms 1556 KB Output is correct
14 Correct 1 ms 1556 KB Output is correct
15 Correct 1 ms 1564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 5616 KB Output is correct
2 Correct 19 ms 5416 KB Output is correct
3 Correct 19 ms 5620 KB Output is correct
4 Correct 11 ms 3640 KB Output is correct
5 Correct 13 ms 4412 KB Output is correct
6 Correct 11 ms 4156 KB Output is correct
7 Correct 13 ms 4152 KB Output is correct
8 Correct 10 ms 4156 KB Output is correct
9 Correct 10 ms 4160 KB Output is correct
10 Correct 9 ms 4000 KB Output is correct
11 Correct 10 ms 3940 KB Output is correct
12 Correct 10 ms 3616 KB Output is correct
13 Correct 10 ms 3616 KB Output is correct
14 Correct 10 ms 3876 KB Output is correct
15 Correct 13 ms 3616 KB Output is correct
16 Correct 12 ms 3760 KB Output is correct
17 Correct 10 ms 3644 KB Output is correct
18 Correct 11 ms 3640 KB Output is correct
19 Correct 10 ms 3640 KB Output is correct
20 Correct 8 ms 4152 KB Output is correct
21 Correct 8 ms 4056 KB Output is correct
22 Correct 13 ms 4156 KB Output is correct
23 Correct 11 ms 4404 KB Output is correct
24 Correct 13 ms 4424 KB Output is correct
25 Correct 12 ms 4164 KB Output is correct
26 Correct 13 ms 4444 KB Output is correct
27 Correct 12 ms 4104 KB Output is correct
28 Correct 14 ms 4472 KB Output is correct
29 Correct 10 ms 4292 KB Output is correct
30 Correct 10 ms 4208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 5408 KB Output is correct
2 Correct 18 ms 5276 KB Output is correct
3 Correct 19 ms 5396 KB Output is correct
4 Correct 12 ms 3656 KB Output is correct
5 Correct 11 ms 4120 KB Output is correct
6 Correct 11 ms 4148 KB Output is correct
7 Correct 11 ms 4156 KB Output is correct
8 Correct 12 ms 4132 KB Output is correct
9 Correct 11 ms 4328 KB Output is correct
10 Correct 11 ms 3936 KB Output is correct
11 Correct 9 ms 3912 KB Output is correct
12 Correct 11 ms 3764 KB Output is correct
13 Correct 12 ms 3700 KB Output is correct
14 Correct 10 ms 3892 KB Output is correct
15 Correct 15 ms 3732 KB Output is correct
16 Correct 11 ms 3696 KB Output is correct
17 Correct 13 ms 3752 KB Output is correct
18 Correct 13 ms 3764 KB Output is correct
19 Correct 11 ms 3668 KB Output is correct
20 Correct 9 ms 4092 KB Output is correct
21 Correct 8 ms 4152 KB Output is correct
22 Correct 11 ms 4056 KB Output is correct
23 Correct 11 ms 4152 KB Output is correct
24 Correct 11 ms 4152 KB Output is correct
25 Correct 11 ms 4144 KB Output is correct
26 Correct 14 ms 4192 KB Output is correct
27 Correct 12 ms 4152 KB Output is correct
28 Correct 12 ms 4112 KB Output is correct
29 Correct 12 ms 4112 KB Output is correct
30 Correct 11 ms 4144 KB Output is correct
31 Correct 2 ms 1576 KB Output is correct
32 Correct 2 ms 1556 KB Output is correct
33 Correct 2 ms 1564 KB Output is correct
34 Correct 1 ms 1556 KB Output is correct
35 Correct 1 ms 1568 KB Output is correct
36 Correct 2 ms 1560 KB Output is correct
37 Correct 2 ms 1648 KB Output is correct
38 Correct 1 ms 1556 KB Output is correct
39 Correct 2 ms 1984 KB Output is correct
40 Correct 2 ms 1556 KB Output is correct
41 Correct 2 ms 1556 KB Output is correct
42 Correct 1 ms 1552 KB Output is correct