Submission #216027

# Submission time Handle Problem Language Result Execution time Memory
216027 2020-03-26T16:00:04 Z eriksuenderhauf Stray Cat (JOI20_stray) C++14
91 / 100
90 ms 17324 KB
#include "Anthony.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define trav(x, a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;

namespace {
  const int N = 2e4 + 5;
  vi adj[N];
  int dp[N];
  string bl = "001011";
}

vi Mark(int N, int M, int A, int B, vi U, vi V) {
  // const int ln = 6;
  // for (int i = 0; i < (1<<ln); i++) {
  //   string cur, xcur;
  //   for (int j = ln-1; ~j; j--) {
  //     cur.pb((char)('0'+((i >> j) & 1)));
  //     xcur.pb(cur.back()^1);
  //   }
  //   string tmp = cur + cur;
  //   int ok = tmp.find(cur, 1) != string::npos;
  //   int o = tmp.find(xcur) != string::npos;
  //   reverse(tmp.begin(), tmp.end());
  //   ok &= ok ^ (tmp.find(cur) != string::npos);
  //   o &= tmp.find(xcur) == string::npos;
  //   if (ok) {
  //     cerr << cur << " " << xcur << endl;
  //   }
  // }
  for (int i = 0; i < M; i++)
    adj[U[i]].pb(i), adj[V[i]].pb(i);
  if (A > 2) {
    deque<int> pq;
    pq.pb(0);
    fill(dp, dp+N, N+1);
    dp[0] = 0;
    vi X(M);
    for (int i = 0; i < M; i++)
      X[i] = 2;
    while (!pq.empty()) {
      int u = pq.front(); pq.pop_front();
      trav(x, adj[u]) {
        int v = U[x]^V[x]^u;
        if (dp[v] > dp[u] + 1) {
          dp[v] = dp[u] + 1;
          pq.pb(v);
        }
        if (dp[v] == dp[u] + 1 || dp[v] == dp[u]) {
          X[x] = dp[u]%3;
        }
      }
    }
    return X;
  }
  vi X(M);
  function<void(int,int,int,int)> dfs = [&](int u, int p, int d, int l) {
    int f = (u != 0 && sz(adj[u]) > 2 ? 1 : 0);
    // cerr << u << " " << f << " " << l << endl;
    trav(x, adj[u]) {
      int v = U[x]^V[x]^u;
      if (v != p) {
        X[x] = f ? l : bl[d%sz(bl)]-'0';
        dfs(v, u, d+(f?0:1), X[x]^1);
      }
    }
  };
  dfs(0, -1, 0, 0);
  // for (int i = 0; i < M; i++)
  //   cerr << U[i] << " " << V[i] << " / " << X[i] << endl;
  return X;
}
#include "Catherine.h"
#include <bits/stdc++.h>
#define vi vector<int>
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;
int A, B;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get(int l, int r) {
  return uniform_int_distribution<int>(l,r)(rng);
}

void Init(int A, int B) {
  ::A = A;
  ::B = B;
}

namespace {
  int lst = -1;
  bool fnd = 0;
  string bl = "001011001011";
  string rbl = "110100110100";
  string cur = "";
}

int Move(vi y) {
  if (A > 2) {
    if (~lst) y[lst]++;
    if (y[0] && y[1])
      return lst = 0;
    if (y[0] && y[2])
      return lst = 2;
    if (y[1] && y[2])
      return lst = 1;
    for (int i = 0; i < 3; i++)
      if (y[i])
        return lst = i;
  }
  if (fnd) {
    if (y[0]+y[1] > 1)
      y[lst]++;
    return lst = (y[0]==1 ? 0 : 1);
  }
  if (lst == -1) {
    if (y[0]+y[1] == 1) {
      fnd = 1;
      return lst = (y[0]==1 ? 0 : 1);
    }
    if (y[0]+y[1] > 2) {
      fnd = 1;
      return lst = (y[0]==1 ? 0 : 1);
    }
    lst = (y[0]>0 ? 0 : 1);
    cur.pb((char)('0'+lst));
    return lst;
  }
  if (y[0]+y[1]==0) {
    fnd = 1;
    return -1;
  }
  if (y[0]+y[1]>1) {
    fnd = 1;
    y[lst]++;
    if (y[lst] == 1)
      return -1;
    return lst = lst^1;
  }
  vector<int> pos;
  for (int i = 0; i < 6; i++) {
    bool fl = 1;
    for (int j = 0; fl && j < sz(cur); j++)
      fl &= cur[j] == bl[i+j];
    if (fl)
      pos.pb(i);
    fl = 1;
    for (int j = 0; fl && j < sz(cur); j++)
      fl &= cur[j] == rbl[i+j];
    if (fl)
      pos.pb(~i);
  }
  if (sz(pos) == 1) {
    // cerr << "found dir: " << pos[0] << "\n";
    fnd = 1;
    if (pos[0] >= 0)
      return -1;
    return lst = (y[0]==1 ? 0 : 1);
  }
  lst = (y[0]==1 ? 0 : 1);
  cur.pb((char)('0'+lst));
  return lst;
}
# Verdict Execution time Memory Grader output
1 Correct 68 ms 16052 KB Output is correct
2 Correct 10 ms 1536 KB Output is correct
3 Correct 63 ms 15148 KB Output is correct
4 Correct 87 ms 17188 KB Output is correct
5 Correct 85 ms 17324 KB Output is correct
6 Correct 64 ms 15804 KB Output is correct
7 Correct 60 ms 15952 KB Output is correct
8 Correct 76 ms 16460 KB Output is correct
9 Correct 84 ms 16528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 16052 KB Output is correct
2 Correct 10 ms 1536 KB Output is correct
3 Correct 63 ms 15148 KB Output is correct
4 Correct 87 ms 17188 KB Output is correct
5 Correct 85 ms 17324 KB Output is correct
6 Correct 64 ms 15804 KB Output is correct
7 Correct 60 ms 15952 KB Output is correct
8 Correct 76 ms 16460 KB Output is correct
9 Correct 84 ms 16528 KB Output is correct
10 Correct 55 ms 13828 KB Output is correct
11 Correct 56 ms 13848 KB Output is correct
12 Correct 54 ms 13896 KB Output is correct
13 Correct 66 ms 13884 KB Output is correct
14 Correct 63 ms 14140 KB Output is correct
15 Correct 70 ms 14516 KB Output is correct
16 Correct 80 ms 16596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13652 KB Output is correct
2 Correct 11 ms 1536 KB Output is correct
3 Correct 56 ms 13088 KB Output is correct
4 Correct 79 ms 14884 KB Output is correct
5 Correct 76 ms 14796 KB Output is correct
6 Correct 57 ms 13780 KB Output is correct
7 Correct 68 ms 13524 KB Output is correct
8 Correct 66 ms 14268 KB Output is correct
9 Correct 66 ms 14284 KB Output is correct
10 Correct 69 ms 14028 KB Output is correct
11 Correct 65 ms 14020 KB Output is correct
12 Correct 63 ms 13900 KB Output is correct
13 Correct 65 ms 14164 KB Output is correct
14 Correct 65 ms 14372 KB Output is correct
15 Correct 63 ms 14308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 13652 KB Output is correct
2 Correct 11 ms 1536 KB Output is correct
3 Correct 56 ms 13088 KB Output is correct
4 Correct 79 ms 14884 KB Output is correct
5 Correct 76 ms 14796 KB Output is correct
6 Correct 57 ms 13780 KB Output is correct
7 Correct 68 ms 13524 KB Output is correct
8 Correct 66 ms 14268 KB Output is correct
9 Correct 66 ms 14284 KB Output is correct
10 Correct 69 ms 14028 KB Output is correct
11 Correct 65 ms 14020 KB Output is correct
12 Correct 63 ms 13900 KB Output is correct
13 Correct 65 ms 14164 KB Output is correct
14 Correct 65 ms 14372 KB Output is correct
15 Correct 63 ms 14308 KB Output is correct
16 Correct 55 ms 12192 KB Output is correct
17 Correct 49 ms 11852 KB Output is correct
18 Correct 56 ms 12068 KB Output is correct
19 Correct 59 ms 11888 KB Output is correct
20 Correct 73 ms 12736 KB Output is correct
21 Correct 59 ms 12516 KB Output is correct
22 Correct 65 ms 14412 KB Output is correct
23 Correct 59 ms 12108 KB Output is correct
24 Correct 60 ms 11964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1536 KB Output is correct
2 Correct 9 ms 1536 KB Output is correct
3 Correct 11 ms 1536 KB Output is correct
4 Correct 10 ms 1792 KB Output is correct
5 Correct 11 ms 1792 KB Output is correct
6 Correct 10 ms 1792 KB Output is correct
7 Correct 10 ms 1792 KB Output is correct
8 Correct 12 ms 1744 KB Output is correct
9 Correct 11 ms 1792 KB Output is correct
10 Correct 10 ms 1792 KB Output is correct
11 Correct 10 ms 1792 KB Output is correct
12 Correct 12 ms 1792 KB Output is correct
13 Correct 10 ms 1792 KB Output is correct
14 Correct 10 ms 1792 KB Output is correct
15 Correct 11 ms 1792 KB Output is correct
16 Correct 14 ms 1536 KB Output is correct
17 Correct 11 ms 1792 KB Output is correct
18 Correct 13 ms 1792 KB Output is correct
19 Correct 10 ms 1792 KB Output is correct
20 Correct 12 ms 1792 KB Output is correct
21 Correct 12 ms 1552 KB Output is correct
22 Correct 11 ms 1792 KB Output is correct
23 Correct 10 ms 1792 KB Output is correct
24 Correct 11 ms 1536 KB Output is correct
25 Correct 11 ms 1792 KB Output is correct
26 Correct 12 ms 1536 KB Output is correct
27 Correct 11 ms 1792 KB Output is correct
28 Correct 11 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 11624 KB Output is correct
2 Correct 68 ms 13132 KB Output is correct
3 Correct 11 ms 1536 KB Output is correct
4 Correct 51 ms 11432 KB Output is correct
5 Correct 79 ms 15056 KB Output is correct
6 Correct 90 ms 15188 KB Output is correct
7 Correct 68 ms 14212 KB Output is correct
8 Correct 60 ms 14164 KB Output is correct
9 Correct 69 ms 15168 KB Output is correct
10 Correct 84 ms 15112 KB Output is correct
11 Correct 73 ms 15172 KB Output is correct
12 Correct 87 ms 15284 KB Output is correct
13 Correct 70 ms 15180 KB Output is correct
14 Correct 86 ms 15044 KB Output is correct
15 Correct 74 ms 15336 KB Output is correct
16 Correct 77 ms 15248 KB Output is correct
17 Correct 69 ms 14796 KB Output is correct
18 Correct 76 ms 14788 KB Output is correct
19 Correct 73 ms 14676 KB Output is correct
20 Correct 75 ms 14788 KB Output is correct
21 Correct 68 ms 14796 KB Output is correct
22 Correct 67 ms 14756 KB Output is correct
23 Correct 59 ms 11596 KB Output is correct
24 Correct 56 ms 11616 KB Output is correct
25 Correct 53 ms 12244 KB Output is correct
26 Correct 58 ms 12244 KB Output is correct
27 Correct 70 ms 13400 KB Output is correct
28 Correct 70 ms 13268 KB Output is correct
29 Correct 60 ms 13372 KB Output is correct
30 Correct 71 ms 13332 KB Output is correct
31 Correct 55 ms 11604 KB Output is correct
32 Correct 55 ms 11656 KB Output is correct
33 Correct 63 ms 12260 KB Output is correct
34 Correct 55 ms 12212 KB Output is correct
35 Correct 57 ms 12992 KB Output is correct
36 Correct 68 ms 12996 KB Output is correct
37 Correct 65 ms 13092 KB Output is correct
38 Correct 66 ms 12884 KB Output is correct
39 Correct 59 ms 12620 KB Output is correct
40 Correct 61 ms 12728 KB Output is correct
41 Correct 66 ms 13476 KB Output is correct
42 Correct 65 ms 13556 KB Output is correct
43 Correct 71 ms 13556 KB Output is correct
44 Correct 79 ms 13556 KB Output is correct
45 Correct 70 ms 13604 KB Output is correct
46 Correct 64 ms 13428 KB Output is correct
47 Correct 66 ms 12412 KB Output is correct
48 Correct 78 ms 12640 KB Output is correct
49 Correct 69 ms 12532 KB Output is correct
50 Correct 57 ms 12520 KB Output is correct
51 Correct 59 ms 11248 KB Output is correct
52 Correct 57 ms 11264 KB Output is correct
53 Correct 62 ms 11184 KB Output is correct
54 Correct 55 ms 11116 KB Output is correct
55 Correct 53 ms 11224 KB Output is correct
56 Correct 54 ms 11260 KB Output is correct
57 Correct 58 ms 11488 KB Output is correct
58 Correct 52 ms 11476 KB Output is correct
59 Correct 63 ms 11380 KB Output is correct
60 Correct 55 ms 11524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11192 KB Output is correct
2 Correct 73 ms 12540 KB Output is correct
3 Correct 10 ms 1536 KB Output is correct
4 Correct 48 ms 10984 KB Output is correct
5 Correct 73 ms 14700 KB Output is correct
6 Correct 68 ms 14700 KB Output is correct
7 Incorrect 58 ms 13812 KB Wrong Answer [6]
8 Halted 0 ms 0 KB -