답안 #417626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417626 2021-06-04T04:20:11 Z maximath_1 Navigation 2 (JOI21_navigation2) C++17
100 / 100
873 ms 876 KB
#include "Anna.h"
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;

/*
	L=14 -> 9 chebyshev_dist <= 1, 4 chebyshev_dist >= 2, 1 compass
	L=13 -> 7 chebyshev_dist <= 1, 4 chebyshev_dist >= 2, 2 different numbers for compass
	L=12 -> 7 chebyshev_dist <= 1, 4 chebyshev_dist >= 2, 1 number for compass
	// for 2 unused groups A and B, one of them must be {(0, 1), (1, 0), (1, 1), (1, -1)} away from the other
	// we can use this as a visual compass
*/

const int xx[] = {0, 1, 1, 1};
const int yy[] = {1, 0, 1, -1};

void Anna(int N, int K, vector<int> R, vector<int> C) {
	int tmp_occ[3][3];
	memset(tmp_occ, 0, sizeof(tmp_occ));
	for(int i = 0; i < K; i ++)
		tmp_occ[R[i] % 3][C[i] % 3] = 1;

	vector<pair<int, int> > unassigned_groups;
	for(int i = 0; i < 3; i ++)
		for(int j = 0; j < 3; j ++)
			if(!tmp_occ[i][j])
				unassigned_groups.push_back({i, j});

	unassigned_groups.resize(2);
	bool is_compass = 0;
	for(int d = 0; d < 4; d ++){
		if(make_pair((unassigned_groups[0].first + 3 + xx[d]) % 3, (unassigned_groups[0].second + 3 + yy[d]) % 3) == unassigned_groups[1])
			is_compass = 1;
	}
	if(!is_compass) swap(unassigned_groups[0], unassigned_groups[1]);

	int group[3][3], cnt = 0;
	for(int i = 0; i < 3; i ++){
		for(int j = 0; j < 3; j ++){
			if(i == 0 && j == 0) group[(unassigned_groups[0].first + i) % 3][(unassigned_groups[0].second + j) % 3] = -1;
			else if((unassigned_groups[0].first + i) % 3 == unassigned_groups[1].first && (unassigned_groups[0].second + j) % 3 == unassigned_groups[1].second)
				group[(unassigned_groups[0].first + i) % 3][(unassigned_groups[0].second + j) % 3] = -1;
			else group[(unassigned_groups[0].first + i) % 3][(unassigned_groups[0].second + j) % 3] = cnt ++;
		}
	}

	for(int i = 0; i < N; i ++){
		for(int j = 0; j < N; j ++){
			int gt = group[i % 3][j % 3];
			if(gt == -1) SetFlag(i, j, 12);
			else{
				int di = R[gt] - i, dj = C[gt] - j;
				if(dj >= 2) SetFlag(i, j, 1);
				else if(dj <= -2) SetFlag(i, j, 2);
				else if(di >= 2) SetFlag(i, j, 3);
				else if(di <= -2) SetFlag(i, j, 4);
				else{
					int cnt = -1, done = 0;
					for(int dx = -1; dx <= 1 && !done; dx ++)
						for(int dy = -1; dy <= 1 && !done; dy ++){
							int ni = i + dx, nj = j + dy;
							if(group[(ni + 3) % 3][(nj + 3) % 3] == -1) continue;
							cnt ++;
							if(ni < 0 || ni >= N || nj < 0 || nj >= N) continue;
							if(ni == R[gt] && nj == C[gt]){
								SetFlag(i, j, cnt + 5);
								done = 1;
								break;
							}
						}
				}
			}
		}
	}
}
#include "Bruno.h"
#include <vector>
#include <iostream>
using namespace std;

const int xxx[] = {0, 1, 1, 1};
const int yyy[] = {1, 0, 1, -1};

vector<int> Bruno(int K, vector<int> value) {
	vector<int> ans(K, 0);

	vector<pair<int, int> > unassigned_groups;
	for(int i = 0; i < 3; i ++){
		for(int j = 0; j < 3; j ++){
			if(value[3 * i + j] == 12)
				unassigned_groups.push_back({i, j});
		}
	}

	bool is_compass = 0;
	for(int d = 0; d < 4; d ++){
		if(make_pair((unassigned_groups[0].first + 3 + xxx[d]) % 3, (unassigned_groups[0].second + 3 + yyy[d]) % 3) == unassigned_groups[1])
			is_compass = 1;
	}
	if(!is_compass) swap(unassigned_groups[0], unassigned_groups[1]);

	int group[3][3], cnt = 0;
	for(int i = 0; i < 3; i ++){
		for(int j = 0; j < 3; j ++){
			if(i == 0 && j == 0) group[(unassigned_groups[0].first + i) % 3][(unassigned_groups[0].second + j) % 3] = -1;
			else if((unassigned_groups[0].first + i) % 3 == unassigned_groups[1].first && (unassigned_groups[0].second + j) % 3 == unassigned_groups[1].second)
				group[(unassigned_groups[0].first + i) % 3][(unassigned_groups[0].second + j) % 3] = -1;
			else group[(unassigned_groups[0].first + i) % 3][(unassigned_groups[0].second + j) % 3] = cnt ++;
		}
	}

	for(int i = 0; i < 3; i ++)
		for(int j = 0; j < 3; j ++){
			int gt = group[i][j], tp = value[3 * i + j];
			if(gt == -1) continue;
			if(tp < 5)
				ans[gt] = tp - 1;
			else{
				tp -= 5;
				int cnt = -1, done = 0;
				for(int dx = -1; dx <= 1 && !done; dx ++)
					for(int dy = -1; dy <= 1 && !done; dy ++){
						int ni = i + dx, nj = j + dy;
						if(group[(ni + 3) % 3][(nj + 3) % 3] == -1) continue;
						cnt ++;
						if(cnt == tp){
							if(nj > 1) ans[gt] = 0;
							else if(nj < 1) ans[gt] = 1;
							else if(ni > 1) ans[gt] = 2;
							else if(ni < 1) ans[gt] = 3;
							else ans[gt] = 4;
						}
					}
			}
		}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 384 KB Output is correct
2 Correct 14 ms 388 KB Output is correct
3 Correct 13 ms 468 KB Output is correct
4 Correct 14 ms 384 KB Output is correct
5 Correct 15 ms 384 KB Output is correct
6 Correct 17 ms 384 KB Output is correct
7 Correct 15 ms 468 KB Output is correct
8 Correct 14 ms 384 KB Output is correct
9 Correct 15 ms 388 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 13 ms 384 KB Output is correct
12 Correct 15 ms 464 KB Output is correct
13 Correct 15 ms 384 KB Output is correct
14 Correct 13 ms 468 KB Output is correct
15 Correct 17 ms 384 KB Output is correct
16 Correct 18 ms 384 KB Output is correct
17 Correct 18 ms 384 KB Output is correct
18 Correct 13 ms 384 KB Output is correct
19 Correct 14 ms 384 KB Output is correct
20 Correct 12 ms 388 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 15 ms 384 KB Output is correct
23 Correct 14 ms 392 KB Output is correct
24 Correct 12 ms 384 KB Output is correct
25 Correct 16 ms 384 KB Output is correct
26 Correct 17 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 15 ms 384 KB Output is correct
29 Correct 16 ms 384 KB Output is correct
30 Correct 16 ms 384 KB Output is correct
31 Correct 16 ms 384 KB Output is correct
32 Correct 13 ms 388 KB Output is correct
33 Correct 11 ms 392 KB Output is correct
34 Correct 15 ms 384 KB Output is correct
35 Correct 16 ms 384 KB Output is correct
36 Correct 13 ms 384 KB Output is correct
37 Correct 13 ms 384 KB Output is correct
38 Correct 12 ms 468 KB Output is correct
39 Correct 18 ms 388 KB Output is correct
40 Correct 16 ms 468 KB Output is correct
41 Correct 18 ms 472 KB Output is correct
42 Correct 16 ms 384 KB Output is correct
43 Correct 17 ms 388 KB Output is correct
44 Correct 13 ms 384 KB Output is correct
45 Correct 16 ms 384 KB Output is correct
46 Correct 15 ms 384 KB Output is correct
47 Correct 19 ms 384 KB Output is correct
48 Correct 14 ms 388 KB Output is correct
49 Correct 18 ms 388 KB Output is correct
50 Correct 16 ms 404 KB Output is correct
51 Correct 13 ms 468 KB Output is correct
52 Correct 17 ms 384 KB Output is correct
53 Correct 28 ms 448 KB Output is correct
54 Correct 17 ms 384 KB Output is correct
55 Correct 19 ms 384 KB Output is correct
56 Correct 20 ms 384 KB Output is correct
57 Correct 23 ms 464 KB Output is correct
58 Correct 25 ms 388 KB Output is correct
59 Correct 19 ms 384 KB Output is correct
60 Correct 20 ms 384 KB Output is correct
61 Correct 17 ms 384 KB Output is correct
62 Correct 17 ms 384 KB Output is correct
63 Correct 20 ms 384 KB Output is correct
64 Correct 17 ms 468 KB Output is correct
65 Correct 18 ms 384 KB Output is correct
66 Correct 17 ms 384 KB Output is correct
67 Correct 19 ms 384 KB Output is correct
68 Correct 15 ms 384 KB Output is correct
69 Correct 20 ms 384 KB Output is correct
70 Correct 18 ms 384 KB Output is correct
71 Correct 17 ms 384 KB Output is correct
72 Correct 17 ms 384 KB Output is correct
73 Correct 19 ms 384 KB Output is correct
74 Correct 17 ms 384 KB Output is correct
75 Correct 19 ms 448 KB Output is correct
76 Correct 21 ms 384 KB Output is correct
77 Correct 16 ms 384 KB Output is correct
78 Correct 18 ms 388 KB Output is correct
79 Correct 19 ms 384 KB Output is correct
80 Correct 18 ms 384 KB Output is correct
81 Correct 22 ms 384 KB Output is correct
82 Correct 20 ms 384 KB Output is correct
83 Correct 22 ms 384 KB Output is correct
84 Correct 17 ms 384 KB Output is correct
85 Correct 23 ms 384 KB Output is correct
86 Correct 19 ms 468 KB Output is correct
87 Correct 19 ms 384 KB Output is correct
88 Correct 19 ms 384 KB Output is correct
89 Correct 17 ms 480 KB Output is correct
90 Correct 17 ms 384 KB Output is correct
91 Correct 18 ms 384 KB Output is correct
92 Correct 17 ms 384 KB Output is correct
93 Correct 16 ms 480 KB Output is correct
94 Correct 22 ms 384 KB Output is correct
95 Correct 17 ms 388 KB Output is correct
96 Correct 19 ms 388 KB Output is correct
97 Correct 19 ms 404 KB Output is correct
98 Correct 17 ms 388 KB Output is correct
99 Correct 22 ms 388 KB Output is correct
100 Correct 16 ms 384 KB Output is correct
101 Correct 16 ms 388 KB Output is correct
102 Correct 18 ms 384 KB Output is correct
103 Correct 23 ms 388 KB Output is correct
104 Correct 17 ms 388 KB Output is correct
105 Correct 19 ms 384 KB Output is correct
106 Correct 17 ms 472 KB Output is correct
107 Correct 15 ms 384 KB Output is correct
108 Correct 18 ms 464 KB Output is correct
109 Correct 20 ms 384 KB Output is correct
110 Correct 21 ms 384 KB Output is correct
111 Correct 18 ms 384 KB Output is correct
112 Correct 15 ms 388 KB Output is correct
113 Correct 22 ms 496 KB Output is correct
114 Correct 18 ms 384 KB Output is correct
115 Correct 18 ms 388 KB Output is correct
116 Correct 18 ms 384 KB Output is correct
117 Correct 17 ms 468 KB Output is correct
118 Correct 19 ms 384 KB Output is correct
119 Correct 21 ms 384 KB Output is correct
120 Correct 775 ms 748 KB Output is correct
121 Correct 844 ms 724 KB Output is correct
122 Correct 737 ms 732 KB Output is correct
123 Correct 847 ms 572 KB Output is correct
124 Correct 775 ms 616 KB Output is correct
125 Correct 802 ms 768 KB Output is correct
126 Correct 755 ms 724 KB Output is correct
127 Correct 782 ms 860 KB Output is correct
128 Correct 729 ms 608 KB Output is correct
129 Correct 743 ms 600 KB Output is correct
130 Correct 781 ms 876 KB Output is correct
131 Correct 748 ms 660 KB Output is correct
132 Correct 774 ms 828 KB Output is correct
133 Correct 790 ms 840 KB Output is correct
134 Correct 749 ms 696 KB Output is correct
135 Correct 780 ms 696 KB Output is correct
136 Correct 775 ms 656 KB Output is correct
137 Correct 756 ms 688 KB Output is correct
138 Correct 873 ms 620 KB Output is correct
139 Correct 746 ms 744 KB Output is correct
140 Correct 794 ms 656 KB Output is correct
141 Correct 728 ms 608 KB Output is correct
142 Correct 759 ms 552 KB Output is correct
143 Correct 811 ms 680 KB Output is correct
144 Correct 742 ms 720 KB Output is correct
145 Correct 781 ms 520 KB Output is correct
146 Correct 766 ms 664 KB Output is correct
147 Correct 735 ms 648 KB Output is correct
148 Correct 759 ms 876 KB Output is correct
149 Correct 770 ms 568 KB Output is correct
150 Correct 767 ms 624 KB Output is correct
151 Correct 779 ms 724 KB Output is correct
152 Correct 787 ms 612 KB Output is correct
153 Correct 763 ms 720 KB Output is correct
154 Correct 737 ms 712 KB Output is correct
155 Correct 773 ms 696 KB Output is correct
156 Correct 803 ms 684 KB Output is correct
157 Correct 819 ms 788 KB Output is correct
158 Correct 768 ms 496 KB Output is correct
159 Correct 764 ms 616 KB Output is correct
160 Correct 801 ms 728 KB Output is correct
161 Correct 746 ms 580 KB Output is correct
162 Correct 753 ms 712 KB Output is correct
163 Correct 805 ms 572 KB Output is correct
164 Correct 806 ms 632 KB Output is correct
165 Correct 746 ms 624 KB Output is correct
166 Correct 738 ms 528 KB Output is correct
167 Correct 751 ms 708 KB Output is correct
168 Correct 744 ms 700 KB Output is correct
169 Correct 736 ms 768 KB Output is correct
170 Correct 777 ms 828 KB Output is correct
171 Correct 732 ms 696 KB Output is correct
172 Correct 733 ms 692 KB Output is correct
173 Correct 722 ms 648 KB Output is correct
174 Correct 741 ms 676 KB Output is correct
175 Correct 725 ms 732 KB Output is correct
176 Correct 750 ms 716 KB Output is correct
177 Correct 736 ms 696 KB Output is correct
178 Correct 727 ms 800 KB Output is correct
179 Correct 734 ms 876 KB Output is correct
180 Correct 735 ms 600 KB Output is correct
181 Correct 781 ms 612 KB Output is correct
182 Correct 751 ms 628 KB Output is correct
183 Correct 736 ms 708 KB Output is correct
184 Correct 743 ms 688 KB Output is correct
185 Correct 756 ms 560 KB Output is correct
186 Correct 736 ms 692 KB Output is correct
187 Correct 726 ms 724 KB Output is correct
188 Correct 751 ms 700 KB Output is correct
189 Correct 751 ms 648 KB Output is correct
190 Correct 741 ms 748 KB Output is correct
191 Correct 754 ms 576 KB Output is correct
192 Correct 740 ms 548 KB Output is correct
193 Correct 743 ms 600 KB Output is correct
194 Correct 765 ms 576 KB Output is correct
195 Correct 790 ms 756 KB Output is correct
196 Correct 749 ms 700 KB Output is correct
197 Correct 751 ms 572 KB Output is correct
198 Correct 754 ms 788 KB Output is correct
199 Correct 730 ms 644 KB Output is correct
200 Correct 734 ms 656 KB Output is correct
201 Correct 737 ms 572 KB Output is correct
202 Correct 728 ms 648 KB Output is correct
203 Correct 764 ms 632 KB Output is correct
204 Correct 719 ms 836 KB Output is correct
205 Correct 757 ms 568 KB Output is correct
206 Correct 732 ms 732 KB Output is correct
207 Correct 717 ms 708 KB Output is correct
208 Correct 736 ms 724 KB Output is correct
209 Correct 776 ms 612 KB Output is correct
210 Correct 549 ms 584 KB Output is correct
211 Correct 571 ms 772 KB Output is correct
212 Correct 609 ms 592 KB Output is correct
213 Correct 629 ms 852 KB Output is correct
214 Correct 584 ms 584 KB Output is correct
215 Correct 543 ms 576 KB Output is correct
216 Correct 603 ms 620 KB Output is correct
217 Correct 555 ms 700 KB Output is correct
218 Correct 553 ms 776 KB Output is correct
219 Correct 560 ms 612 KB Output is correct
220 Correct 545 ms 584 KB Output is correct
221 Correct 656 ms 656 KB Output is correct
222 Correct 594 ms 688 KB Output is correct
223 Correct 570 ms 800 KB Output is correct
224 Correct 566 ms 624 KB Output is correct
225 Correct 646 ms 676 KB Output is correct
226 Correct 556 ms 672 KB Output is correct