Submission #216942

# Submission time Handle Problem Language Result Execution time Memory
216942 2020-03-28T13:33:56 Z eriksuenderhauf Stray Cat (JOI20_stray) C++14
100 / 100
75 ms 17144 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) {
  for (int i = 0; i < M; i++)
    adj[U[i]].pb(i), adj[V[i]].pb(i);
  vi X(M);
  if (A > 2) {
    deque<int> pq;
    pq.pb(0);
    fill(dp, dp+N, N+1);
    dp[0] = 0;
    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;
  }
  function<void(int,int,int,int)> dfs = [&](int u, int p, int d, int l) {
    if (u != 0 && sz(adj[u]) > 2) d = l ? 0 : 2;
    trav(x, adj[u]) {
      int v = U[x]^V[x]^u;
      if (v != p) {
        X[x] = bl[d%sz(bl)]-'0';
        dfs(v, u, d+1, X[x]);
      }
    }
  };
  dfs(0, -1, 0, 0);
  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;

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);
    y[lst]--;
    cur.pb(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;
  }
  cur.pb((y[0] == 1 ? '0' : '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) {
    fnd = 1;
    return pos[0] >= 0 ? -1 : (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 65 ms 15960 KB Output is correct
2 Correct 9 ms 1536 KB Output is correct
3 Correct 46 ms 15300 KB Output is correct
4 Correct 65 ms 17144 KB Output is correct
5 Correct 65 ms 17132 KB Output is correct
6 Correct 53 ms 15676 KB Output is correct
7 Correct 54 ms 15696 KB Output is correct
8 Correct 62 ms 16496 KB Output is correct
9 Correct 64 ms 16488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 15960 KB Output is correct
2 Correct 9 ms 1536 KB Output is correct
3 Correct 46 ms 15300 KB Output is correct
4 Correct 65 ms 17144 KB Output is correct
5 Correct 65 ms 17132 KB Output is correct
6 Correct 53 ms 15676 KB Output is correct
7 Correct 54 ms 15696 KB Output is correct
8 Correct 62 ms 16496 KB Output is correct
9 Correct 64 ms 16488 KB Output is correct
10 Correct 49 ms 13748 KB Output is correct
11 Correct 49 ms 13732 KB Output is correct
12 Correct 49 ms 13740 KB Output is correct
13 Correct 49 ms 13748 KB Output is correct
14 Correct 62 ms 13936 KB Output is correct
15 Correct 55 ms 14320 KB Output is correct
16 Correct 60 ms 16628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 13428 KB Output is correct
2 Correct 10 ms 1536 KB Output is correct
3 Correct 46 ms 12924 KB Output is correct
4 Correct 72 ms 14700 KB Output is correct
5 Correct 63 ms 14956 KB Output is correct
6 Correct 51 ms 13508 KB Output is correct
7 Correct 55 ms 13492 KB Output is correct
8 Correct 59 ms 14256 KB Output is correct
9 Correct 60 ms 14076 KB Output is correct
10 Correct 54 ms 13908 KB Output is correct
11 Correct 56 ms 14052 KB Output is correct
12 Correct 75 ms 14056 KB Output is correct
13 Correct 54 ms 14036 KB Output is correct
14 Correct 60 ms 14204 KB Output is correct
15 Correct 59 ms 14308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 13428 KB Output is correct
2 Correct 10 ms 1536 KB Output is correct
3 Correct 46 ms 12924 KB Output is correct
4 Correct 72 ms 14700 KB Output is correct
5 Correct 63 ms 14956 KB Output is correct
6 Correct 51 ms 13508 KB Output is correct
7 Correct 55 ms 13492 KB Output is correct
8 Correct 59 ms 14256 KB Output is correct
9 Correct 60 ms 14076 KB Output is correct
10 Correct 54 ms 13908 KB Output is correct
11 Correct 56 ms 14052 KB Output is correct
12 Correct 75 ms 14056 KB Output is correct
13 Correct 54 ms 14036 KB Output is correct
14 Correct 60 ms 14204 KB Output is correct
15 Correct 59 ms 14308 KB Output is correct
16 Correct 48 ms 12004 KB Output is correct
17 Correct 46 ms 12000 KB Output is correct
18 Correct 49 ms 11824 KB Output is correct
19 Correct 57 ms 11812 KB Output is correct
20 Correct 54 ms 12408 KB Output is correct
21 Correct 52 ms 12204 KB Output is correct
22 Correct 56 ms 14428 KB Output is correct
23 Correct 49 ms 11956 KB Output is correct
24 Correct 49 ms 11800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1792 KB Output is correct
2 Correct 9 ms 1536 KB Output is correct
3 Correct 10 ms 1536 KB Output is correct
4 Correct 10 ms 1792 KB Output is correct
5 Correct 10 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 10 ms 1792 KB Output is correct
9 Correct 10 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 10 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 10 ms 1792 KB Output is correct
16 Correct 10 ms 1552 KB Output is correct
17 Correct 10 ms 1792 KB Output is correct
18 Correct 11 ms 1792 KB Output is correct
19 Correct 10 ms 1564 KB Output is correct
20 Correct 10 ms 1536 KB Output is correct
21 Correct 10 ms 1536 KB Output is correct
22 Correct 10 ms 1792 KB Output is correct
23 Correct 10 ms 1812 KB Output is correct
24 Correct 10 ms 1536 KB Output is correct
25 Correct 10 ms 1812 KB Output is correct
26 Correct 11 ms 1792 KB Output is correct
27 Correct 10 ms 1792 KB Output is correct
28 Correct 10 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11532 KB Output is correct
2 Correct 53 ms 13044 KB Output is correct
3 Correct 10 ms 1536 KB Output is correct
4 Correct 42 ms 11500 KB Output is correct
5 Correct 67 ms 14824 KB Output is correct
6 Correct 59 ms 14680 KB Output is correct
7 Correct 51 ms 13936 KB Output is correct
8 Correct 51 ms 13804 KB Output is correct
9 Correct 60 ms 14708 KB Output is correct
10 Correct 59 ms 14800 KB Output is correct
11 Correct 59 ms 14928 KB Output is correct
12 Correct 60 ms 14676 KB Output is correct
13 Correct 60 ms 14696 KB Output is correct
14 Correct 60 ms 14700 KB Output is correct
15 Correct 59 ms 14708 KB Output is correct
16 Correct 61 ms 14824 KB Output is correct
17 Correct 57 ms 14420 KB Output is correct
18 Correct 67 ms 14436 KB Output is correct
19 Correct 57 ms 14672 KB Output is correct
20 Correct 62 ms 14372 KB Output is correct
21 Correct 56 ms 14444 KB Output is correct
22 Correct 67 ms 14692 KB Output is correct
23 Correct 48 ms 11612 KB Output is correct
24 Correct 49 ms 11604 KB Output is correct
25 Correct 50 ms 12332 KB Output is correct
26 Correct 50 ms 12200 KB Output is correct
27 Correct 55 ms 13204 KB Output is correct
28 Correct 61 ms 13184 KB Output is correct
29 Correct 54 ms 13140 KB Output is correct
30 Correct 61 ms 13148 KB Output is correct
31 Correct 50 ms 12056 KB Output is correct
32 Correct 48 ms 11804 KB Output is correct
33 Correct 50 ms 12248 KB Output is correct
34 Correct 50 ms 12104 KB Output is correct
35 Correct 57 ms 13016 KB Output is correct
36 Correct 56 ms 13012 KB Output is correct
37 Correct 54 ms 13032 KB Output is correct
38 Correct 54 ms 13012 KB Output is correct
39 Correct 53 ms 13032 KB Output is correct
40 Correct 58 ms 13012 KB Output is correct
41 Correct 55 ms 13852 KB Output is correct
42 Correct 56 ms 13844 KB Output is correct
43 Correct 59 ms 13840 KB Output is correct
44 Correct 59 ms 13976 KB Output is correct
45 Correct 56 ms 13840 KB Output is correct
46 Correct 56 ms 13840 KB Output is correct
47 Correct 56 ms 12996 KB Output is correct
48 Correct 53 ms 12984 KB Output is correct
49 Correct 52 ms 12864 KB Output is correct
50 Correct 53 ms 12884 KB Output is correct
51 Correct 50 ms 12056 KB Output is correct
52 Correct 51 ms 11976 KB Output is correct
53 Correct 50 ms 12060 KB Output is correct
54 Correct 49 ms 12100 KB Output is correct
55 Correct 49 ms 12068 KB Output is correct
56 Correct 53 ms 12080 KB Output is correct
57 Correct 50 ms 11860 KB Output is correct
58 Correct 49 ms 11988 KB Output is correct
59 Correct 53 ms 12092 KB Output is correct
60 Correct 53 ms 12080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 11888 KB Output is correct
2 Correct 52 ms 12676 KB Output is correct
3 Correct 9 ms 1536 KB Output is correct
4 Correct 44 ms 11496 KB Output is correct
5 Correct 61 ms 14708 KB Output is correct
6 Correct 63 ms 14708 KB Output is correct
7 Correct 49 ms 13940 KB Output is correct
8 Correct 50 ms 13796 KB Output is correct
9 Correct 60 ms 14688 KB Output is correct
10 Correct 61 ms 14692 KB Output is correct
11 Correct 61 ms 14704 KB Output is correct
12 Correct 63 ms 14916 KB Output is correct
13 Correct 63 ms 14924 KB Output is correct
14 Correct 60 ms 14924 KB Output is correct
15 Correct 61 ms 14704 KB Output is correct
16 Correct 69 ms 14828 KB Output is correct
17 Correct 64 ms 14768 KB Output is correct
18 Correct 57 ms 14664 KB Output is correct
19 Correct 59 ms 14436 KB Output is correct
20 Correct 67 ms 14672 KB Output is correct
21 Correct 56 ms 14448 KB Output is correct
22 Correct 57 ms 14548 KB Output is correct
23 Correct 49 ms 11600 KB Output is correct
24 Correct 49 ms 11660 KB Output is correct
25 Correct 50 ms 12180 KB Output is correct
26 Correct 53 ms 12332 KB Output is correct
27 Correct 55 ms 13200 KB Output is correct
28 Correct 55 ms 13200 KB Output is correct
29 Correct 56 ms 13424 KB Output is correct
30 Correct 56 ms 13176 KB Output is correct
31 Correct 48 ms 11792 KB Output is correct
32 Correct 50 ms 11800 KB Output is correct
33 Correct 53 ms 12316 KB Output is correct
34 Correct 64 ms 12288 KB Output is correct
35 Correct 55 ms 13044 KB Output is correct
36 Correct 54 ms 13028 KB Output is correct
37 Correct 55 ms 13148 KB Output is correct
38 Correct 70 ms 13244 KB Output is correct
39 Correct 54 ms 13036 KB Output is correct
40 Correct 56 ms 13032 KB Output is correct
41 Correct 61 ms 13696 KB Output is correct
42 Correct 57 ms 13692 KB Output is correct
43 Correct 57 ms 13860 KB Output is correct
44 Correct 56 ms 13984 KB Output is correct
45 Correct 61 ms 13844 KB Output is correct
46 Correct 59 ms 13820 KB Output is correct
47 Correct 54 ms 12884 KB Output is correct
48 Correct 56 ms 12988 KB Output is correct
49 Correct 52 ms 12860 KB Output is correct
50 Correct 54 ms 12988 KB Output is correct
51 Correct 52 ms 12080 KB Output is correct
52 Correct 55 ms 12096 KB Output is correct
53 Correct 50 ms 11860 KB Output is correct
54 Correct 53 ms 12088 KB Output is correct
55 Correct 49 ms 12076 KB Output is correct
56 Correct 54 ms 12108 KB Output is correct
57 Correct 50 ms 11988 KB Output is correct
58 Correct 51 ms 11952 KB Output is correct
59 Correct 51 ms 12084 KB Output is correct
60 Correct 52 ms 12528 KB Output is correct