Submission #883799

# Submission time Handle Problem Language Result Execution time Memory
883799 2023-12-06T04:59:43 Z marvinthang Stray Cat (JOI20_stray) C++17
100 / 100
40 ms 16348 KB
/*************************************
*    author: marvinthang             *
*    created: 06.12.2023 09:33:05    *
*************************************/

#include "Anthony.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i-- > 0; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

namespace {

}

vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) {
	vector <vector <int>> adj(N);
	REP(i, M) {
		adj[U[i]].push_back(i);
		adj[V[i]].push_back(i);
	}
	vector <int> res(M);
	if (A >= 3) {
		queue <int> q;
		q.push(0);
		vector <int> dist(N, -1);
		dist[0] = 0;
		while (!q.empty()){
			int u = q.front(); q.pop();
			for (int i: adj[u]) {
				int v = U[i] ^ V[i] ^ u;
				if (dist[v] == -1) {
					dist[v] = dist[u] + 1;
					q.push(v);
				}
				if (dist[v] == dist[u] + 1) res[i] = dist[v] % 3;
				else if (dist[v] == dist[u]) res[i] = (dist[u] + 1) % 3;
			}
		}
	} else {
		int pattern = 11; // 001011
		int pos_0 = __builtin_ctz(pattern + 1);
		int pos_1 = __builtin_ctz(pattern);
		function<void(int, int, int)> dfs = [&] (int u, int par, int t) {
			if (adj[u].size() >= 3) {
				if (t >= 0) {
					t = (t + 5) % 6;
					if (BIT(pattern, t)) t = -1;
					else t = -2;
				}
				if (t >= 0) t = -1;
				for (int i: adj[u]) {
					int v = U[i] ^ V[i] ^ u;
					if (v == par) {
						assert(res[i] == !(-1 - t));
						continue;
					}
					res[i] = -1 - t;
					dfs(v, u, -3 - t);
				}
			} else {
				if (t < 0) {
					if (t == -1) t = pos_0;
					else t = pos_1;
				}
				for (int i: adj[u]) {
					int v = U[i] ^ V[i] ^ u;
					if (v == par) continue;
					res[i] = BIT(pattern, t);
					dfs(v, u, (t + 1) % 6);
				}
			}
		};
		dfs(0, 0, 0);
	}
	return res;
}
#include "Catherine.h"
/*************************************
*    author: marvinthang             *
*    created: 06.12.2023 09:38:51    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i-- > 0; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

namespace {
	int A, cur_mask, len, last;
	set <int> exist[7];
}

void Init(int A, int B) {
	::A = A;
	vector <int> pattern {0, 0, 1, 0, 1, 1};
	pattern.insert(pattern.end(), ALL(pattern));
	exist[0].insert(0);
	REP(i, 6) {
		int mask = 0;
		REP(j, 6) {
			mask = mask << 1 | pattern[i + j];
			exist[j + 1].insert(mask);
		}
	}
	cur_mask = len = 0;
	last = -1;
}

int Move(vector<int> y) {
	if (A >= 3) {
		REP(i, 3) if (y[i] && !y[(i + 2) % 3]) return i;
	} else {
		if (y[0] + y[1] + (last >= 0) >= 3) {
			len = 6;
			if (!y[0] || !y[1]) return -1;
			if (last == -1) return last = y[1] == 1;
			return last = !last;
		}
		if (y[0] + y[1] + (last >= 0) == 1) {
			len = 6;
			return last >= 0 ? -1 : last = y[1] == 1;
		}
		REP(i, 2) if (y[i]) {
			if (last == -1) {
				len = 1;
				cur_mask = y[1] - i;
			}
			cur_mask = cur_mask << 1 | i;
			if (len < 6 && !exist[++len].count(cur_mask)) {
				len = 6;
				return -1;
			}
			return last = i;
		}
	}
}

Compilation message

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:94:1: warning: control reaches end of non-void function [-Wreturn-type]
   94 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 37 ms 15228 KB Output is correct
2 Correct 0 ms 776 KB Output is correct
3 Correct 23 ms 14528 KB Output is correct
4 Correct 33 ms 16256 KB Output is correct
5 Correct 34 ms 16348 KB Output is correct
6 Correct 28 ms 15024 KB Output is correct
7 Correct 28 ms 14924 KB Output is correct
8 Correct 32 ms 15744 KB Output is correct
9 Correct 32 ms 15744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 15228 KB Output is correct
2 Correct 0 ms 776 KB Output is correct
3 Correct 23 ms 14528 KB Output is correct
4 Correct 33 ms 16256 KB Output is correct
5 Correct 34 ms 16348 KB Output is correct
6 Correct 28 ms 15024 KB Output is correct
7 Correct 28 ms 14924 KB Output is correct
8 Correct 32 ms 15744 KB Output is correct
9 Correct 32 ms 15744 KB Output is correct
10 Correct 26 ms 13188 KB Output is correct
11 Correct 29 ms 13144 KB Output is correct
12 Correct 28 ms 13288 KB Output is correct
13 Correct 27 ms 13040 KB Output is correct
14 Correct 27 ms 13292 KB Output is correct
15 Correct 31 ms 13548 KB Output is correct
16 Correct 30 ms 15732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12672 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 23 ms 12500 KB Output is correct
4 Correct 33 ms 14220 KB Output is correct
5 Correct 31 ms 14084 KB Output is correct
6 Correct 31 ms 12712 KB Output is correct
7 Correct 27 ms 12704 KB Output is correct
8 Correct 32 ms 13476 KB Output is correct
9 Correct 31 ms 13408 KB Output is correct
10 Correct 31 ms 13184 KB Output is correct
11 Correct 27 ms 13188 KB Output is correct
12 Correct 30 ms 13188 KB Output is correct
13 Correct 30 ms 13184 KB Output is correct
14 Correct 35 ms 13392 KB Output is correct
15 Correct 33 ms 13440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12672 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 23 ms 12500 KB Output is correct
4 Correct 33 ms 14220 KB Output is correct
5 Correct 31 ms 14084 KB Output is correct
6 Correct 31 ms 12712 KB Output is correct
7 Correct 27 ms 12704 KB Output is correct
8 Correct 32 ms 13476 KB Output is correct
9 Correct 31 ms 13408 KB Output is correct
10 Correct 31 ms 13184 KB Output is correct
11 Correct 27 ms 13188 KB Output is correct
12 Correct 30 ms 13188 KB Output is correct
13 Correct 30 ms 13184 KB Output is correct
14 Correct 35 ms 13392 KB Output is correct
15 Correct 33 ms 13440 KB Output is correct
16 Correct 23 ms 11180 KB Output is correct
17 Correct 25 ms 11064 KB Output is correct
18 Correct 24 ms 10988 KB Output is correct
19 Correct 24 ms 10988 KB Output is correct
20 Correct 26 ms 11720 KB Output is correct
21 Correct 26 ms 11500 KB Output is correct
22 Correct 28 ms 13696 KB Output is correct
23 Correct 26 ms 11248 KB Output is correct
24 Correct 27 ms 11244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1052 KB Output is correct
2 Correct 0 ms 780 KB Output is correct
3 Correct 1 ms 1552 KB Output is correct
4 Correct 2 ms 1052 KB Output is correct
5 Correct 2 ms 1044 KB Output is correct
6 Correct 1 ms 1036 KB Output is correct
7 Correct 1 ms 1056 KB Output is correct
8 Correct 2 ms 1044 KB Output is correct
9 Correct 2 ms 1052 KB Output is correct
10 Correct 2 ms 1048 KB Output is correct
11 Correct 1 ms 1052 KB Output is correct
12 Correct 2 ms 1044 KB Output is correct
13 Correct 2 ms 1052 KB Output is correct
14 Correct 1 ms 1052 KB Output is correct
15 Correct 1 ms 1048 KB Output is correct
16 Correct 2 ms 1044 KB Output is correct
17 Correct 1 ms 1044 KB Output is correct
18 Correct 0 ms 1052 KB Output is correct
19 Correct 2 ms 1048 KB Output is correct
20 Correct 1 ms 1036 KB Output is correct
21 Correct 1 ms 1044 KB Output is correct
22 Correct 2 ms 1052 KB Output is correct
23 Correct 2 ms 1048 KB Output is correct
24 Correct 1 ms 1300 KB Output is correct
25 Correct 1 ms 1036 KB Output is correct
26 Correct 2 ms 1044 KB Output is correct
27 Correct 1 ms 1052 KB Output is correct
28 Correct 2 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10884 KB Output is correct
2 Correct 27 ms 12416 KB Output is correct
3 Correct 0 ms 792 KB Output is correct
4 Correct 22 ms 10624 KB Output is correct
5 Correct 31 ms 14268 KB Output is correct
6 Correct 31 ms 14256 KB Output is correct
7 Correct 27 ms 13232 KB Output is correct
8 Correct 27 ms 13220 KB Output is correct
9 Correct 32 ms 14464 KB Output is correct
10 Correct 36 ms 14268 KB Output is correct
11 Correct 32 ms 14096 KB Output is correct
12 Correct 32 ms 14216 KB Output is correct
13 Correct 31 ms 14256 KB Output is correct
14 Correct 31 ms 14256 KB Output is correct
15 Correct 31 ms 14240 KB Output is correct
16 Correct 32 ms 14156 KB Output is correct
17 Correct 30 ms 13988 KB Output is correct
18 Correct 28 ms 13960 KB Output is correct
19 Correct 30 ms 13992 KB Output is correct
20 Correct 30 ms 13984 KB Output is correct
21 Correct 30 ms 13956 KB Output is correct
22 Correct 30 ms 13996 KB Output is correct
23 Correct 25 ms 10888 KB Output is correct
24 Correct 25 ms 10880 KB Output is correct
25 Correct 30 ms 11704 KB Output is correct
26 Correct 25 ms 11652 KB Output is correct
27 Correct 27 ms 12444 KB Output is correct
28 Correct 27 ms 12680 KB Output is correct
29 Correct 28 ms 12960 KB Output is correct
30 Correct 27 ms 13116 KB Output is correct
31 Correct 27 ms 10880 KB Output is correct
32 Correct 25 ms 10880 KB Output is correct
33 Correct 31 ms 11652 KB Output is correct
34 Correct 34 ms 11564 KB Output is correct
35 Correct 27 ms 12324 KB Output is correct
36 Correct 27 ms 12420 KB Output is correct
37 Correct 27 ms 12432 KB Output is correct
38 Correct 28 ms 12396 KB Output is correct
39 Correct 27 ms 12496 KB Output is correct
40 Correct 28 ms 12376 KB Output is correct
41 Correct 28 ms 13324 KB Output is correct
42 Correct 27 ms 13184 KB Output is correct
43 Correct 31 ms 13240 KB Output is correct
44 Correct 28 ms 13424 KB Output is correct
45 Correct 30 ms 13400 KB Output is correct
46 Correct 31 ms 13140 KB Output is correct
47 Correct 27 ms 12116 KB Output is correct
48 Correct 28 ms 12172 KB Output is correct
49 Correct 26 ms 11944 KB Output is correct
50 Correct 27 ms 12208 KB Output is correct
51 Correct 25 ms 11212 KB Output is correct
52 Correct 26 ms 11384 KB Output is correct
53 Correct 26 ms 11392 KB Output is correct
54 Correct 31 ms 11328 KB Output is correct
55 Correct 26 ms 11396 KB Output is correct
56 Correct 26 ms 11396 KB Output is correct
57 Correct 24 ms 11396 KB Output is correct
58 Correct 24 ms 11392 KB Output is correct
59 Correct 25 ms 11124 KB Output is correct
60 Correct 25 ms 11124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 10836 KB Output is correct
2 Correct 27 ms 12168 KB Output is correct
3 Correct 0 ms 776 KB Output is correct
4 Correct 22 ms 10824 KB Output is correct
5 Correct 31 ms 14132 KB Output is correct
6 Correct 31 ms 14248 KB Output is correct
7 Correct 27 ms 13228 KB Output is correct
8 Correct 27 ms 13660 KB Output is correct
9 Correct 32 ms 14724 KB Output is correct
10 Correct 31 ms 14760 KB Output is correct
11 Correct 31 ms 14760 KB Output is correct
12 Correct 33 ms 14652 KB Output is correct
13 Correct 32 ms 14624 KB Output is correct
14 Correct 31 ms 14624 KB Output is correct
15 Correct 31 ms 14612 KB Output is correct
16 Correct 35 ms 14648 KB Output is correct
17 Correct 28 ms 14432 KB Output is correct
18 Correct 40 ms 14420 KB Output is correct
19 Correct 28 ms 14316 KB Output is correct
20 Correct 28 ms 14264 KB Output is correct
21 Correct 31 ms 14432 KB Output is correct
22 Correct 28 ms 14444 KB Output is correct
23 Correct 24 ms 11352 KB Output is correct
24 Correct 26 ms 11340 KB Output is correct
25 Correct 26 ms 11892 KB Output is correct
26 Correct 26 ms 11904 KB Output is correct
27 Correct 28 ms 12896 KB Output is correct
28 Correct 27 ms 13148 KB Output is correct
29 Correct 28 ms 13052 KB Output is correct
30 Correct 28 ms 13100 KB Output is correct
31 Correct 24 ms 11516 KB Output is correct
32 Correct 24 ms 11308 KB Output is correct
33 Correct 25 ms 11908 KB Output is correct
34 Correct 26 ms 11744 KB Output is correct
35 Correct 27 ms 12676 KB Output is correct
36 Correct 27 ms 12816 KB Output is correct
37 Correct 34 ms 12892 KB Output is correct
38 Correct 28 ms 12676 KB Output is correct
39 Correct 28 ms 12872 KB Output is correct
40 Correct 27 ms 12680 KB Output is correct
41 Correct 30 ms 13860 KB Output is correct
42 Correct 30 ms 13712 KB Output is correct
43 Correct 27 ms 13708 KB Output is correct
44 Correct 30 ms 13520 KB Output is correct
45 Correct 31 ms 13656 KB Output is correct
46 Correct 28 ms 13644 KB Output is correct
47 Correct 28 ms 12584 KB Output is correct
48 Correct 27 ms 12628 KB Output is correct
49 Correct 26 ms 12376 KB Output is correct
50 Correct 30 ms 12516 KB Output is correct
51 Correct 25 ms 11832 KB Output is correct
52 Correct 26 ms 11864 KB Output is correct
53 Correct 25 ms 11848 KB Output is correct
54 Correct 25 ms 11868 KB Output is correct
55 Correct 26 ms 11868 KB Output is correct
56 Correct 25 ms 11864 KB Output is correct
57 Correct 26 ms 11860 KB Output is correct
58 Correct 26 ms 11860 KB Output is correct
59 Correct 27 ms 11688 KB Output is correct
60 Correct 28 ms 11620 KB Output is correct