답안 #670648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670648 2022-12-09T19:41:55 Z rainboy 길고양이 (JOI20_stray) C++17
100 / 100
49 ms 16552 KB
#include "Anthony.h"
#include <cstdlib>
#include <vector>
 
using namespace std;
 
typedef vector<int> vi;
 
namespace A {
	const int N = 20000;
	const int zz[] = { 0, 1, 0, 0, 1, 1 };
 
	int min(int a, int b) { return a < b ? a : b; }
 
	int *ej[N], eo[N], dd[N], pp[N], cc_[N], qu[N], n;
 
	void init(int n_) {
		n = n_;
		for (int i = 0; i < n; i++)
			ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	}
 
	void append(int i, int j) {
		int o = eo[i]++;
		if (o >= 2 && (o & o - 1) == 0)
			ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
		ej[i][o] = j;
	}
 
	void bfs() {
		for (int i = 0; i < n; i++)
			dd[i] = n;
		int cnt = 0;
		dd[0] = 0, qu[cnt++] = 0;
		for (int h = 0; h < cnt; h++) {
			int i = qu[h], d = dd[i] + 1;
			for (int o = eo[i]; o--; ) {
				int j = ej[i][o];
				if (dd[j] > d)
					dd[j] = d, qu[cnt++] = j;
			}
		}
	}
	void dfs(int p, int i, int c) {
		pp[i] = p;
		for (int o = eo[i]; o--; ) {
			int j = ej[i][o];
			if (j != p) {
				if (p == -1)
					cc_[j] = 0, dfs(i, j, 0);
				else if (eo[i] == 2)
					cc_[j] = zz[(c + 1) % 6], dfs(i, j, (c + 1) % 6);
				else
					cc_[j] = zz[c % 6] ^ 1, dfs(i, j, zz[c % 6] ^ 1);
			}
		}
	}
}
 
vi Mark(int n, int m, int a, int b, vi uu, vi vv) {
	vi cc(m);
	if (a >= 3 && b == 0) {
		A::init(n);
		for (int h = 0; h < m; h++)
			A::append(uu[h], vv[h]), A::append(vv[h], uu[h]);
		A::bfs();
		for (int h = 0; h < m; h++)
			cc[h] = A::min(A::dd[uu[h]], A::dd[vv[h]]) % 3;
	} else {
		A::init(n);
		for (int h = 0; h < m; h++)
			A::append(uu[h], vv[h]), A::append(vv[h], uu[h]);
		A::dfs(-1, 0, -1);
		for (int h = 0; h < m; h++) {
			int i = A::pp[uu[h]] == vv[h] ? uu[h] : vv[h];
			cc[h] = A::cc_[i];
		}
	}
	return cc;
}
#include "Catherine.h"
#include <vector>
 
using namespace std;
 
typedef vector<int> vi;
 
namespace C {
	const int zz[] = { 0, 1, 0, 0, 1, 1 };
	int cc[6], h, c_;
}
 
void Init(int a, int b) {
	a = b = a;
	C::h = 0, C::c_ = -1;
}
 
int Move(vi kk) {
	int a = kk.size();
	if (a >= 3) {
		for (int c = 0; c < 3; c++)
			if (kk[(c + 2) % 3] == 0 && kk[c] != 0)
				return c;
		return -1;
	} else {
		int d = C::c_ != -1 ? 1 : 0;
		for (int c = 0; c < 2; c++)
			d += kk[c];
		if (d == 1) {
			C::h = -1;
			for (int c = 0; c < 2; c++)
				if (kk[c] != 0)
					return C::c_ = c;
			return -1;
		} else if (d == 2) {
			if (C::h == -1) {
				for (int c = 0; c < 2; c++)
					if (kk[c] != 0)
						return C::c_ = c;
				return -1;
			} else {
				for (int c = 0; c < 2; c++)
					while (kk[c] > 0)
						C::cc[C::h++] = c, kk[c]--;
				if (C::h < 5)
					return C::c_ = C::cc[C::h - 1];
				else {
					for (int g = 0; g < 6; g++) {
						int match = 1;
						for (int h = 0; h < 5; h++)
							if (C::cc[h] != C::zz[(g + h) % 6]) {
								match = 0;
								break;
							}
						if (match) {
							C::h = -1;
							return -1;
						}
					}
					C::h = -1;
					return C::c_ = C::cc[4];
				}
			}
		} else {
			C::h = -1;
			return C::c_ == -1 ? (kk[0] == 1 ? 0 : 1) : kk[C::c_] == 0 ? -1 : (C::c_ ^= 1);
		}
	}
}

Compilation message

Anthony.cpp: In function 'void A::append(int, int)':
Anthony.cpp:25:24: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   25 |   if (o >= 2 && (o & o - 1) == 0)
      |                      ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 15140 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 27 ms 14564 KB Output is correct
4 Correct 44 ms 16552 KB Output is correct
5 Correct 45 ms 16320 KB Output is correct
6 Correct 34 ms 14944 KB Output is correct
7 Correct 33 ms 15044 KB Output is correct
8 Correct 39 ms 15584 KB Output is correct
9 Correct 41 ms 15792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 15140 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 27 ms 14564 KB Output is correct
4 Correct 44 ms 16552 KB Output is correct
5 Correct 45 ms 16320 KB Output is correct
6 Correct 34 ms 14944 KB Output is correct
7 Correct 33 ms 15044 KB Output is correct
8 Correct 39 ms 15584 KB Output is correct
9 Correct 41 ms 15792 KB Output is correct
10 Correct 31 ms 13032 KB Output is correct
11 Correct 32 ms 13012 KB Output is correct
12 Correct 30 ms 12992 KB Output is correct
13 Correct 32 ms 12884 KB Output is correct
14 Correct 31 ms 13312 KB Output is correct
15 Correct 37 ms 13564 KB Output is correct
16 Correct 38 ms 15812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 12764 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 31 ms 12344 KB Output is correct
4 Correct 41 ms 14184 KB Output is correct
5 Correct 41 ms 14132 KB Output is correct
6 Correct 31 ms 12780 KB Output is correct
7 Correct 31 ms 12768 KB Output is correct
8 Correct 36 ms 13412 KB Output is correct
9 Correct 36 ms 13420 KB Output is correct
10 Correct 34 ms 13096 KB Output is correct
11 Correct 35 ms 13156 KB Output is correct
12 Correct 35 ms 13188 KB Output is correct
13 Correct 35 ms 13156 KB Output is correct
14 Correct 37 ms 13444 KB Output is correct
15 Correct 36 ms 13436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 12764 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 31 ms 12344 KB Output is correct
4 Correct 41 ms 14184 KB Output is correct
5 Correct 41 ms 14132 KB Output is correct
6 Correct 31 ms 12780 KB Output is correct
7 Correct 31 ms 12768 KB Output is correct
8 Correct 36 ms 13412 KB Output is correct
9 Correct 36 ms 13420 KB Output is correct
10 Correct 34 ms 13096 KB Output is correct
11 Correct 35 ms 13156 KB Output is correct
12 Correct 35 ms 13188 KB Output is correct
13 Correct 35 ms 13156 KB Output is correct
14 Correct 37 ms 13444 KB Output is correct
15 Correct 36 ms 13436 KB Output is correct
16 Correct 28 ms 11232 KB Output is correct
17 Correct 32 ms 11060 KB Output is correct
18 Correct 40 ms 11084 KB Output is correct
19 Correct 30 ms 11136 KB Output is correct
20 Correct 33 ms 11744 KB Output is correct
21 Correct 33 ms 11432 KB Output is correct
22 Correct 37 ms 13648 KB Output is correct
23 Correct 31 ms 11412 KB Output is correct
24 Correct 35 ms 11280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 908 KB Output is correct
2 Correct 0 ms 516 KB Output is correct
3 Correct 0 ms 904 KB Output is correct
4 Correct 2 ms 904 KB Output is correct
5 Correct 2 ms 904 KB Output is correct
6 Correct 2 ms 896 KB Output is correct
7 Correct 2 ms 904 KB Output is correct
8 Correct 2 ms 904 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
11 Correct 2 ms 896 KB Output is correct
12 Correct 2 ms 904 KB Output is correct
13 Correct 1 ms 896 KB Output is correct
14 Correct 1 ms 864 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 0 ms 904 KB Output is correct
18 Correct 2 ms 896 KB Output is correct
19 Correct 2 ms 896 KB Output is correct
20 Correct 2 ms 896 KB Output is correct
21 Correct 2 ms 904 KB Output is correct
22 Correct 1 ms 904 KB Output is correct
23 Correct 2 ms 896 KB Output is correct
24 Correct 1 ms 896 KB Output is correct
25 Correct 2 ms 892 KB Output is correct
26 Correct 0 ms 904 KB Output is correct
27 Correct 2 ms 904 KB Output is correct
28 Correct 1 ms 900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 10960 KB Output is correct
2 Correct 34 ms 12264 KB Output is correct
3 Correct 0 ms 504 KB Output is correct
4 Correct 27 ms 10736 KB Output is correct
5 Correct 44 ms 14000 KB Output is correct
6 Correct 45 ms 13936 KB Output is correct
7 Correct 32 ms 13160 KB Output is correct
8 Correct 34 ms 13172 KB Output is correct
9 Correct 40 ms 14012 KB Output is correct
10 Correct 39 ms 14008 KB Output is correct
11 Correct 41 ms 14320 KB Output is correct
12 Correct 39 ms 14400 KB Output is correct
13 Correct 40 ms 13972 KB Output is correct
14 Correct 39 ms 14384 KB Output is correct
15 Correct 38 ms 14040 KB Output is correct
16 Correct 44 ms 13952 KB Output is correct
17 Correct 42 ms 13788 KB Output is correct
18 Correct 42 ms 14088 KB Output is correct
19 Correct 41 ms 14048 KB Output is correct
20 Correct 38 ms 14060 KB Output is correct
21 Correct 35 ms 14140 KB Output is correct
22 Correct 35 ms 14208 KB Output is correct
23 Correct 30 ms 11436 KB Output is correct
24 Correct 31 ms 11524 KB Output is correct
25 Correct 34 ms 11880 KB Output is correct
26 Correct 31 ms 11824 KB Output is correct
27 Correct 35 ms 12780 KB Output is correct
28 Correct 37 ms 12856 KB Output is correct
29 Correct 34 ms 12952 KB Output is correct
30 Correct 35 ms 12848 KB Output is correct
31 Correct 33 ms 11396 KB Output is correct
32 Correct 31 ms 11372 KB Output is correct
33 Correct 31 ms 11752 KB Output is correct
34 Correct 30 ms 11920 KB Output is correct
35 Correct 35 ms 12640 KB Output is correct
36 Correct 34 ms 12812 KB Output is correct
37 Correct 32 ms 12852 KB Output is correct
38 Correct 34 ms 12776 KB Output is correct
39 Correct 36 ms 12664 KB Output is correct
40 Correct 34 ms 12872 KB Output is correct
41 Correct 35 ms 13440 KB Output is correct
42 Correct 38 ms 13496 KB Output is correct
43 Correct 49 ms 13392 KB Output is correct
44 Correct 35 ms 13548 KB Output is correct
45 Correct 35 ms 13460 KB Output is correct
46 Correct 39 ms 13460 KB Output is correct
47 Correct 34 ms 12476 KB Output is correct
48 Correct 36 ms 12516 KB Output is correct
49 Correct 32 ms 12400 KB Output is correct
50 Correct 33 ms 12500 KB Output is correct
51 Correct 28 ms 11584 KB Output is correct
52 Correct 38 ms 11488 KB Output is correct
53 Correct 32 ms 11584 KB Output is correct
54 Correct 32 ms 11688 KB Output is correct
55 Correct 33 ms 11840 KB Output is correct
56 Correct 33 ms 11548 KB Output is correct
57 Correct 36 ms 11556 KB Output is correct
58 Correct 30 ms 11512 KB Output is correct
59 Correct 28 ms 11628 KB Output is correct
60 Correct 31 ms 11624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 10932 KB Output is correct
2 Correct 33 ms 12244 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 25 ms 10920 KB Output is correct
5 Correct 38 ms 14072 KB Output is correct
6 Correct 39 ms 14064 KB Output is correct
7 Correct 33 ms 13132 KB Output is correct
8 Correct 31 ms 13532 KB Output is correct
9 Correct 38 ms 14004 KB Output is correct
10 Correct 39 ms 13988 KB Output is correct
11 Correct 37 ms 14032 KB Output is correct
12 Correct 37 ms 14008 KB Output is correct
13 Correct 39 ms 13956 KB Output is correct
14 Correct 49 ms 13968 KB Output is correct
15 Correct 38 ms 14044 KB Output is correct
16 Correct 40 ms 14424 KB Output is correct
17 Correct 37 ms 14216 KB Output is correct
18 Correct 43 ms 14064 KB Output is correct
19 Correct 35 ms 14004 KB Output is correct
20 Correct 38 ms 14116 KB Output is correct
21 Correct 35 ms 14112 KB Output is correct
22 Correct 39 ms 14068 KB Output is correct
23 Correct 35 ms 11364 KB Output is correct
24 Correct 31 ms 11332 KB Output is correct
25 Correct 31 ms 11876 KB Output is correct
26 Correct 30 ms 11920 KB Output is correct
27 Correct 35 ms 12764 KB Output is correct
28 Correct 40 ms 12852 KB Output is correct
29 Correct 37 ms 12864 KB Output is correct
30 Correct 35 ms 12868 KB Output is correct
31 Correct 28 ms 11380 KB Output is correct
32 Correct 30 ms 11480 KB Output is correct
33 Correct 30 ms 11876 KB Output is correct
34 Correct 31 ms 11960 KB Output is correct
35 Correct 34 ms 12816 KB Output is correct
36 Correct 33 ms 12764 KB Output is correct
37 Correct 34 ms 12848 KB Output is correct
38 Correct 33 ms 12760 KB Output is correct
39 Correct 34 ms 12808 KB Output is correct
40 Correct 35 ms 12808 KB Output is correct
41 Correct 39 ms 13472 KB Output is correct
42 Correct 39 ms 13400 KB Output is correct
43 Correct 39 ms 13392 KB Output is correct
44 Correct 36 ms 13504 KB Output is correct
45 Correct 35 ms 13404 KB Output is correct
46 Correct 36 ms 13472 KB Output is correct
47 Correct 34 ms 12532 KB Output is correct
48 Correct 34 ms 12500 KB Output is correct
49 Correct 31 ms 12448 KB Output is correct
50 Correct 35 ms 12460 KB Output is correct
51 Correct 30 ms 11720 KB Output is correct
52 Correct 33 ms 11500 KB Output is correct
53 Correct 34 ms 11540 KB Output is correct
54 Correct 32 ms 11732 KB Output is correct
55 Correct 30 ms 11560 KB Output is correct
56 Correct 30 ms 11824 KB Output is correct
57 Correct 31 ms 11512 KB Output is correct
58 Correct 32 ms 11540 KB Output is correct
59 Correct 35 ms 11636 KB Output is correct
60 Correct 31 ms 11712 KB Output is correct