답안 #700242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700242 2023-02-19T02:30:56 Z cig32 Amusement Park (JOI17_amusement_park) C++17
100 / 100
31 ms 4432 KB
#include "Joi.h"
#include "bits/stdc++.h"
using namespace std;

static vector<int> adj2[12269];
static bool vis2[12269];
static int val2[12269];
static int nxt2;
static void dfs2(int node, long long X, int par) {
  val2[node] = nxt2;
  nxt2 = (nxt2 + 1) % 60;
  long long res = (X & (1ll << val2[node]));
  if(res > 0) res = 1;
  MessageBoard(node, (int) res);
  vis2[node] = 1;
  for(int x: adj2[node]) {
    if(!vis2[x]) {
      dfs2(x, X, node);
    }
  }
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
  for(int i=0; i<M; i++) {
    adj2[A[i]].push_back(B[i]);
    adj2[B[i]].push_back(A[i]);
  }
  for(int i=0; i<N; i++) {
    sort(adj2[i].begin(), adj2[i].end());
  }
  for(int i=0; i<N; i++) {
    vis2[i] = 0;
  }
  dfs2(0, X, -1);
}

#include "Ioi.h"
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e4 + 10;
static vector<int> adj[MAXN];
static bool vis[MAXN];
static int val[MAXN];
static int sz[MAXN];
static int nxt;
static vector<int> et;
static int p[MAXN];
static void dfs(int node, int par) {
  val[node] = nxt;
  nxt = (nxt+1) % 60;
  vis[node] = 1;
  sz[node] = 1;
  p[node] = par;
  et.push_back(node);
  for(int x: adj[node]) {
    if(!vis[x]) {
      dfs(x, node);
      et.push_back(node);
      sz[node] += sz[x];
    }
  }
}
 
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  nxt = 0;
  et.clear();
  for(int i=0; i<N; i++) {
    adj[i].clear();
  }
  for(int i=0; i<M; i++) {
    adj[A[i]].push_back(B[i]);
    adj[B[i]].push_back(A[i]);
  }
  for(int i=0; i<N; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  for(int i=0; i<N; i++) {
    vis[i] = 0;
  }
  dfs(0, -1);
  long long ans = 0;
  int res[60];
  for(int i=0; i<60; i++) res[i] = -1;
  res[val[P]] = V;
  int l[N];
  for(int i=0; i<N; i++) l[i] = -1;
  for(int i=0; i<et.size(); i++) {
    if(l[et[i]] == -1) l[et[i]] = i;
  }
  int node = P, idx = l[P];
  et.pop_back();
  if(sz[node]>=60) {
    set<int> st;
    st.insert(val[P]);
    while(st.size() != 60) {
      idx++;
      node = et[idx];
      res[val[node]] = Move(node);
      st.insert(val[node]);
    }
  }
  else {
    int optc = 60;
    int optd = 1;
    for(int c=10; c<=180; c++) {
      set<int>st;
      st.insert(val[P]);
      int qcnt=0;
      int nd=node;
      int ii=idx;
      for(int i=0; sz[nd]<min(N,c); i++) {
        if(p[nd] != -1) {
          nd=p[nd];
          ii=l[nd];
          st.insert(val[nd]);
          qcnt++;
        }
        else break;
      }
      while(st.size() != 60) {
        ii++;
        ii %= (int) et.size();
        nd = et[ii];
        qcnt++;
        st.insert(val[nd]);
      }
      if(qcnt <= 120) optc = c, optd = 1;
      // next
      st.clear();
      st.insert(val[P]);
      qcnt = 0, nd = node, ii = idx;
      for(int i=0; sz[nd]<min(N,c); i++) {
        if(p[nd] != -1) {
          nd=p[nd];
          ii=l[nd];
          st.insert(val[nd]);
          qcnt++;
        }
        else break;
      }
      while(st.size() != 60) {
        ii--;
        ii += (int) et.size();
        ii %= (int) et.size();
        nd = et[ii];
        qcnt++;
        st.insert(val[nd]);
      }
      if(qcnt <= 120) optc = c, optd = -1;
    }
    set<int>st;
    st.insert(val[P]);
    for(int i=0; sz[node]<min(N,optc); i++) {
      if(p[node] != -1) {
        node=p[node];
        idx=l[node];
        res[val[node]]=Move(node);
        st.insert(val[node]);
      }
      else break;
    }
    while(st.size() != 60) {
      idx += optd;
      idx += (int) et.size();
      idx %= (int) et.size();
      node = et[idx];
      res[val[node]] = Move(node);
      st.insert(val[node]);
    }
 
  }
 
  for(int i=0; i<60; i++) {
    if(res[i]) ans += (1ll << i);
  }
  return ans;
}

Compilation message

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int i=0; i<et.size(); i++) {
      |                ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 2 ms 1280 KB Output is correct
3 Correct 3 ms 1284 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1284 KB Output is correct
8 Correct 1 ms 1284 KB Output is correct
9 Correct 3 ms 1284 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1456 KB Output is correct
12 Correct 2 ms 1160 KB Output is correct
13 Correct 2 ms 1284 KB Output is correct
14 Correct 3 ms 1284 KB Output is correct
15 Correct 3 ms 1284 KB Output is correct
16 Correct 2 ms 1284 KB Output is correct
17 Correct 3 ms 1288 KB Output is correct
18 Correct 3 ms 1292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4308 KB Output is correct
2 Correct 23 ms 4312 KB Output is correct
3 Correct 25 ms 4412 KB Output is correct
4 Correct 14 ms 2884 KB Output is correct
5 Correct 15 ms 3520 KB Output is correct
6 Correct 15 ms 3564 KB Output is correct
7 Correct 15 ms 3264 KB Output is correct
8 Correct 14 ms 3424 KB Output is correct
9 Correct 15 ms 3412 KB Output is correct
10 Correct 12 ms 3016 KB Output is correct
11 Correct 14 ms 3024 KB Output is correct
12 Correct 11 ms 2868 KB Output is correct
13 Correct 15 ms 2880 KB Output is correct
14 Correct 13 ms 2884 KB Output is correct
15 Correct 14 ms 2924 KB Output is correct
16 Correct 14 ms 2896 KB Output is correct
17 Correct 12 ms 2892 KB Output is correct
18 Correct 13 ms 2872 KB Output is correct
19 Correct 14 ms 2908 KB Output is correct
20 Correct 12 ms 3484 KB Output is correct
21 Correct 11 ms 3528 KB Output is correct
22 Correct 15 ms 3140 KB Output is correct
23 Correct 14 ms 3396 KB Output is correct
24 Correct 14 ms 3280 KB Output is correct
25 Correct 14 ms 3276 KB Output is correct
26 Correct 14 ms 3396 KB Output is correct
27 Correct 13 ms 3392 KB Output is correct
28 Correct 14 ms 3404 KB Output is correct
29 Correct 13 ms 3180 KB Output is correct
30 Correct 13 ms 3260 KB Output is correct
31 Correct 3 ms 1156 KB Output is correct
32 Correct 4 ms 1160 KB Output is correct
33 Correct 2 ms 1280 KB Output is correct
34 Correct 1 ms 1152 KB Output is correct
35 Correct 2 ms 1160 KB Output is correct
36 Correct 3 ms 1160 KB Output is correct
37 Correct 3 ms 1160 KB Output is correct
38 Correct 3 ms 1116 KB Output is correct
39 Correct 3 ms 1160 KB Output is correct
40 Correct 2 ms 1160 KB Output is correct
41 Correct 2 ms 1156 KB Output is correct
42 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1160 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
3 Correct 3 ms 1160 KB Output is correct
4 Correct 2 ms 1564 KB Output is correct
5 Correct 2 ms 1564 KB Output is correct
6 Correct 2 ms 1568 KB Output is correct
7 Correct 2 ms 1576 KB Output is correct
8 Correct 4 ms 1572 KB Output is correct
9 Correct 13 ms 4160 KB Output is correct
10 Correct 13 ms 4080 KB Output is correct
11 Correct 11 ms 4164 KB Output is correct
12 Correct 3 ms 1160 KB Output is correct
13 Correct 3 ms 1160 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 4340 KB Output is correct
2 Correct 30 ms 4368 KB Output is correct
3 Correct 24 ms 4352 KB Output is correct
4 Correct 13 ms 2884 KB Output is correct
5 Correct 15 ms 3792 KB Output is correct
6 Correct 15 ms 3404 KB Output is correct
7 Correct 13 ms 3388 KB Output is correct
8 Correct 12 ms 3140 KB Output is correct
9 Correct 13 ms 3264 KB Output is correct
10 Correct 16 ms 2996 KB Output is correct
11 Correct 14 ms 2996 KB Output is correct
12 Correct 15 ms 2852 KB Output is correct
13 Correct 14 ms 2868 KB Output is correct
14 Correct 19 ms 2884 KB Output is correct
15 Correct 13 ms 2884 KB Output is correct
16 Correct 18 ms 2872 KB Output is correct
17 Correct 16 ms 2884 KB Output is correct
18 Correct 14 ms 2888 KB Output is correct
19 Correct 16 ms 2952 KB Output is correct
20 Correct 12 ms 3524 KB Output is correct
21 Correct 16 ms 3524 KB Output is correct
22 Correct 17 ms 3248 KB Output is correct
23 Correct 14 ms 3256 KB Output is correct
24 Correct 16 ms 3276 KB Output is correct
25 Correct 15 ms 3336 KB Output is correct
26 Correct 16 ms 3356 KB Output is correct
27 Correct 15 ms 3536 KB Output is correct
28 Correct 17 ms 3176 KB Output is correct
29 Correct 14 ms 3164 KB Output is correct
30 Correct 15 ms 3220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 4316 KB Output is correct
2 Correct 31 ms 4432 KB Output is correct
3 Correct 28 ms 4380 KB Output is correct
4 Correct 17 ms 2976 KB Output is correct
5 Correct 18 ms 3908 KB Output is correct
6 Correct 15 ms 3216 KB Output is correct
7 Correct 14 ms 3256 KB Output is correct
8 Correct 19 ms 3312 KB Output is correct
9 Correct 15 ms 3380 KB Output is correct
10 Correct 14 ms 2832 KB Output is correct
11 Correct 15 ms 2884 KB Output is correct
12 Correct 14 ms 2868 KB Output is correct
13 Correct 15 ms 2872 KB Output is correct
14 Correct 18 ms 2832 KB Output is correct
15 Correct 16 ms 2884 KB Output is correct
16 Correct 17 ms 2832 KB Output is correct
17 Correct 16 ms 2832 KB Output is correct
18 Correct 17 ms 2912 KB Output is correct
19 Correct 15 ms 2888 KB Output is correct
20 Correct 12 ms 3500 KB Output is correct
21 Correct 12 ms 3532 KB Output is correct
22 Correct 15 ms 3248 KB Output is correct
23 Correct 15 ms 3276 KB Output is correct
24 Correct 17 ms 3396 KB Output is correct
25 Correct 15 ms 3268 KB Output is correct
26 Correct 14 ms 3128 KB Output is correct
27 Correct 18 ms 3524 KB Output is correct
28 Correct 15 ms 3456 KB Output is correct
29 Correct 13 ms 3252 KB Output is correct
30 Correct 15 ms 3208 KB Output is correct
31 Correct 3 ms 1160 KB Output is correct
32 Correct 1 ms 1160 KB Output is correct
33 Correct 2 ms 1284 KB Output is correct
34 Correct 5 ms 1280 KB Output is correct
35 Correct 3 ms 1152 KB Output is correct
36 Correct 3 ms 1152 KB Output is correct
37 Correct 3 ms 1160 KB Output is correct
38 Correct 3 ms 1160 KB Output is correct
39 Correct 3 ms 1164 KB Output is correct
40 Correct 3 ms 1156 KB Output is correct
41 Correct 3 ms 1156 KB Output is correct
42 Correct 3 ms 1164 KB Output is correct