Submission #415124

# Submission time Handle Problem Language Result Execution time Memory
415124 2021-05-31T14:49:22 Z Namnamseo Navigation 2 (JOI21_navigation2) C++17
100 / 100
937 ms 892 KB
#include "Anna.h"
#include <utility>
using namespace std;
using pii=pair<int,int>;

namespace {
pii pos[7];

// [     10      ]
//      1 2 3 
// 11 | 4 5 6 | 13
//      7 8 9
// [     12     ]
//
int opinion(int r, int c, int target)
{
	int dr = pos[target].first - r;
	int dc = pos[target].second - c;
	if (dr >= 2) return 12;
	if (dc >= 2) return 13;
	if (dr <= -2) return 10;
	if (dc <= -2) return 11;
	return (dr+1)*3 + (dc+1) + 1;
}

int ancr, ancc, off;
int get_type(int r, int c) { return (r+3-ancr)%3 * 3 + (c+3-ancc)%3; }
void find_anchor()
{
	for (ancr=0; ancr<3; ++ancr) for (ancc=0; ancc<3; ++ancc) {
		bool ok = 1;
		for (int i=0; i<7; ++i) {
			auto [r, c] = pos[i];
			int nine_type = get_type(r-1, c-1);
			if (nine_type == i) {
				ok = 0; break;
			}
		}
		if (ok) return;
	}
}
bool is_anchor(int i, int j) { return i%3 == ancr && j%3 == ancc; }

int raw[110][110];
bool is_used[20];

}

void Anna(int n, int k, vector<int> r, vector<int> c)
{
	for (int i=0; i<k; ++i) pos[i] = {r[i], c[i]};
	find_anchor();

	for (int i=0; i<n; ++i) {
		for (int j=0; j<n; ++j) {
			int type = get_type(i, j);
			if (type < 7) {
				raw[i][j] = opinion(i, j, type);
			} else if (type == 7) {
				raw[i][j] = 14;
			} else {
				raw[i][j] = 14;
			}
		}
	}

	for (int i=1; i<=14; ++i) is_used[i] = false;
	for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) {
		is_used[raw[i][j]] = true;
	}

	if (is_used[9]) throw "oh no";
	int hi = -1;
	for (int i=1; i<9; ++i) if (!is_used[i]) { hi = i; break; }

	for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) {
		int ans;
		switch(get_type(i, j)) {
		case 8: ans = 12; break;
		case 7: ans = hi; break;
		default:
			int v = raw[i][j];
			if (v >= 9) ans = v-2;
			else if (v >= hi) ans = v-1;
			else ans = v;
		}
		SetFlag(i, j, ans);
	}
}
#include "Bruno.h"
#include <iostream>
using namespace std;

vector<int> Bruno(int k, vector<int> value)
{
	int val_map[3][3];
	int type_map[3][3];
	for (int i=0; i<9; ++i) val_map[i/3][i%3] = value[i];
	int ar, ac;
	[&]{ for (ar=0; ar<3; ++ar) for (ac=0; ac<3; ++ac) {
		if (val_map[ar][ac] == 12) return;
	} }();
	for (int dr=0; dr<3; ++dr) for (int dc=0; dc<3; ++dc) {
		type_map[(ar+dr)%3][(ac+dc)%3] = (
			((dr+2)%3)*3 + (dc+2)%3
		);
	}

	int hi;
	for (int r=0; r<3; ++r) for (int c=0; c<3; ++c) if (type_map[r][c] == 7) {
		hi = val_map[r][c];
	}

	for (int r=0; r<3; ++r) for (int c=0; c<3; ++c) if (type_map[r][c] != 8) {
		int &v = val_map[r][c];
		if (v >= hi) ++v;
		if (v >= 9) ++v;
	}

	vector<int> ret;
	for (int i=0; i<7; ++i) {
		int tr, tc;
		[&]{ for (tr=0; tr<3; ++tr) for (tc=0; tc<3; ++tc) {
			if (type_map[tr][tc] == i) return;
		} }();

		int v = val_map[tr][tc];
		int ans;

		if (v == 10) ans = 3;
		else if (v == 11) ans = 1;
		else if (v == 12) ans = 2;
		else if (v == 13) ans = 0;
		else {
			int dr = (v-1)/3 - 1;
			int dc = (v-1)%3 - 1;

			int ir = tr+dr, ic = tc+dc;
			if (ir == 1 && ic == 1) {
				ans = 4;
			} else if (ir <= 0) {
				ans = 3;
			} else if (ir >= 2) {
				ans = 2;
			} else if (ic <= 0) {
				ans = 1;
			} else if (ic >= 2) {
				ans = 0;
			}
		}

		ret.push_back(ans);
	}

	return ret;
}

Compilation message

Anna.cpp:42:6: warning: 'bool {anonymous}::is_anchor(int, int)' defined but not used [-Wunused-function]
   42 | bool is_anchor(int i, int j) { return i%3 == ancr && j%3 == ancc; }
      |      ^~~~~~~~~
Anna.cpp:26:17: warning: '{anonymous}::off' defined but not used [-Wunused-variable]
   26 | int ancr, ancc, off;
      |                 ^~~

Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:27:3: warning: 'hi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |   if (v >= hi) ++v;
      |   ^~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 10 ms 384 KB Output is correct
3 Correct 15 ms 384 KB Output is correct
4 Correct 15 ms 388 KB Output is correct
5 Correct 17 ms 384 KB Output is correct
6 Correct 17 ms 384 KB Output is correct
7 Correct 19 ms 384 KB Output is correct
8 Correct 19 ms 384 KB Output is correct
9 Correct 15 ms 388 KB Output is correct
10 Correct 15 ms 384 KB Output is correct
11 Correct 16 ms 388 KB Output is correct
12 Correct 17 ms 384 KB Output is correct
13 Correct 15 ms 384 KB Output is correct
14 Correct 19 ms 384 KB Output is correct
15 Correct 18 ms 384 KB Output is correct
16 Correct 17 ms 384 KB Output is correct
17 Correct 14 ms 384 KB Output is correct
18 Correct 16 ms 384 KB Output is correct
19 Correct 17 ms 384 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 13 ms 384 KB Output is correct
23 Correct 19 ms 384 KB Output is correct
24 Correct 19 ms 464 KB Output is correct
25 Correct 19 ms 436 KB Output is correct
26 Correct 15 ms 384 KB Output is correct
27 Correct 19 ms 388 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 20 ms 388 KB Output is correct
30 Correct 19 ms 384 KB Output is correct
31 Correct 15 ms 388 KB Output is correct
32 Correct 20 ms 384 KB Output is correct
33 Correct 14 ms 384 KB Output is correct
34 Correct 19 ms 384 KB Output is correct
35 Correct 23 ms 384 KB Output is correct
36 Correct 16 ms 384 KB Output is correct
37 Correct 16 ms 384 KB Output is correct
38 Correct 16 ms 384 KB Output is correct
39 Correct 17 ms 576 KB Output is correct
40 Correct 18 ms 388 KB Output is correct
41 Correct 18 ms 384 KB Output is correct
42 Correct 18 ms 384 KB Output is correct
43 Correct 17 ms 384 KB Output is correct
44 Correct 16 ms 388 KB Output is correct
45 Correct 18 ms 468 KB Output is correct
46 Correct 14 ms 384 KB Output is correct
47 Correct 19 ms 384 KB Output is correct
48 Correct 16 ms 384 KB Output is correct
49 Correct 19 ms 384 KB Output is correct
50 Correct 18 ms 384 KB Output is correct
51 Correct 18 ms 384 KB Output is correct
52 Correct 19 ms 468 KB Output is correct
53 Correct 18 ms 384 KB Output is correct
54 Correct 16 ms 464 KB Output is correct
55 Correct 15 ms 384 KB Output is correct
56 Correct 24 ms 384 KB Output is correct
57 Correct 22 ms 384 KB Output is correct
58 Correct 19 ms 384 KB Output is correct
59 Correct 20 ms 384 KB Output is correct
60 Correct 16 ms 512 KB Output is correct
61 Correct 20 ms 384 KB Output is correct
62 Correct 20 ms 384 KB Output is correct
63 Correct 20 ms 384 KB Output is correct
64 Correct 26 ms 384 KB Output is correct
65 Correct 22 ms 384 KB Output is correct
66 Correct 22 ms 384 KB Output is correct
67 Correct 23 ms 384 KB Output is correct
68 Correct 20 ms 384 KB Output is correct
69 Correct 24 ms 384 KB Output is correct
70 Correct 20 ms 388 KB Output is correct
71 Correct 24 ms 384 KB Output is correct
72 Correct 23 ms 384 KB Output is correct
73 Correct 20 ms 384 KB Output is correct
74 Correct 20 ms 384 KB Output is correct
75 Correct 20 ms 384 KB Output is correct
76 Correct 22 ms 384 KB Output is correct
77 Correct 17 ms 468 KB Output is correct
78 Correct 26 ms 384 KB Output is correct
79 Correct 22 ms 384 KB Output is correct
80 Correct 18 ms 388 KB Output is correct
81 Correct 26 ms 384 KB Output is correct
82 Correct 22 ms 404 KB Output is correct
83 Correct 17 ms 516 KB Output is correct
84 Correct 18 ms 384 KB Output is correct
85 Correct 24 ms 384 KB Output is correct
86 Correct 19 ms 384 KB Output is correct
87 Correct 20 ms 384 KB Output is correct
88 Correct 19 ms 384 KB Output is correct
89 Correct 16 ms 384 KB Output is correct
90 Correct 24 ms 384 KB Output is correct
91 Correct 22 ms 384 KB Output is correct
92 Correct 24 ms 384 KB Output is correct
93 Correct 20 ms 384 KB Output is correct
94 Correct 20 ms 384 KB Output is correct
95 Correct 23 ms 384 KB Output is correct
96 Correct 24 ms 384 KB Output is correct
97 Correct 23 ms 384 KB Output is correct
98 Correct 20 ms 384 KB Output is correct
99 Correct 24 ms 392 KB Output is correct
100 Correct 24 ms 384 KB Output is correct
101 Correct 19 ms 468 KB Output is correct
102 Correct 25 ms 384 KB Output is correct
103 Correct 17 ms 468 KB Output is correct
104 Correct 20 ms 384 KB Output is correct
105 Correct 23 ms 384 KB Output is correct
106 Correct 16 ms 384 KB Output is correct
107 Correct 17 ms 384 KB Output is correct
108 Correct 20 ms 384 KB Output is correct
109 Correct 26 ms 404 KB Output is correct
110 Correct 20 ms 384 KB Output is correct
111 Correct 20 ms 384 KB Output is correct
112 Correct 21 ms 388 KB Output is correct
113 Correct 20 ms 468 KB Output is correct
114 Correct 19 ms 388 KB Output is correct
115 Correct 19 ms 468 KB Output is correct
116 Correct 24 ms 384 KB Output is correct
117 Correct 20 ms 384 KB Output is correct
118 Correct 19 ms 388 KB Output is correct
119 Correct 22 ms 388 KB Output is correct
120 Correct 811 ms 812 KB Output is correct
121 Correct 782 ms 668 KB Output is correct
122 Correct 801 ms 660 KB Output is correct
123 Correct 769 ms 708 KB Output is correct
124 Correct 710 ms 708 KB Output is correct
125 Correct 781 ms 664 KB Output is correct
126 Correct 721 ms 728 KB Output is correct
127 Correct 811 ms 652 KB Output is correct
128 Correct 703 ms 744 KB Output is correct
129 Correct 726 ms 644 KB Output is correct
130 Correct 685 ms 636 KB Output is correct
131 Correct 724 ms 680 KB Output is correct
132 Correct 731 ms 612 KB Output is correct
133 Correct 692 ms 636 KB Output is correct
134 Correct 756 ms 768 KB Output is correct
135 Correct 731 ms 564 KB Output is correct
136 Correct 815 ms 772 KB Output is correct
137 Correct 733 ms 608 KB Output is correct
138 Correct 763 ms 652 KB Output is correct
139 Correct 734 ms 780 KB Output is correct
140 Correct 765 ms 792 KB Output is correct
141 Correct 741 ms 632 KB Output is correct
142 Correct 745 ms 724 KB Output is correct
143 Correct 752 ms 704 KB Output is correct
144 Correct 713 ms 692 KB Output is correct
145 Correct 699 ms 772 KB Output is correct
146 Correct 763 ms 584 KB Output is correct
147 Correct 712 ms 756 KB Output is correct
148 Correct 740 ms 668 KB Output is correct
149 Correct 721 ms 644 KB Output is correct
150 Correct 763 ms 732 KB Output is correct
151 Correct 711 ms 636 KB Output is correct
152 Correct 786 ms 708 KB Output is correct
153 Correct 754 ms 636 KB Output is correct
154 Correct 689 ms 656 KB Output is correct
155 Correct 718 ms 664 KB Output is correct
156 Correct 705 ms 568 KB Output is correct
157 Correct 755 ms 776 KB Output is correct
158 Correct 752 ms 704 KB Output is correct
159 Correct 736 ms 652 KB Output is correct
160 Correct 748 ms 644 KB Output is correct
161 Correct 760 ms 588 KB Output is correct
162 Correct 846 ms 704 KB Output is correct
163 Correct 856 ms 624 KB Output is correct
164 Correct 937 ms 648 KB Output is correct
165 Correct 686 ms 600 KB Output is correct
166 Correct 737 ms 756 KB Output is correct
167 Correct 692 ms 856 KB Output is correct
168 Correct 702 ms 584 KB Output is correct
169 Correct 721 ms 620 KB Output is correct
170 Correct 709 ms 792 KB Output is correct
171 Correct 803 ms 788 KB Output is correct
172 Correct 763 ms 596 KB Output is correct
173 Correct 770 ms 716 KB Output is correct
174 Correct 698 ms 732 KB Output is correct
175 Correct 710 ms 716 KB Output is correct
176 Correct 820 ms 768 KB Output is correct
177 Correct 736 ms 632 KB Output is correct
178 Correct 716 ms 640 KB Output is correct
179 Correct 744 ms 812 KB Output is correct
180 Correct 715 ms 776 KB Output is correct
181 Correct 715 ms 756 KB Output is correct
182 Correct 714 ms 744 KB Output is correct
183 Correct 692 ms 544 KB Output is correct
184 Correct 856 ms 612 KB Output is correct
185 Correct 696 ms 632 KB Output is correct
186 Correct 702 ms 744 KB Output is correct
187 Correct 698 ms 652 KB Output is correct
188 Correct 799 ms 732 KB Output is correct
189 Correct 761 ms 736 KB Output is correct
190 Correct 698 ms 712 KB Output is correct
191 Correct 715 ms 800 KB Output is correct
192 Correct 718 ms 748 KB Output is correct
193 Correct 700 ms 688 KB Output is correct
194 Correct 707 ms 588 KB Output is correct
195 Correct 740 ms 636 KB Output is correct
196 Correct 696 ms 724 KB Output is correct
197 Correct 694 ms 748 KB Output is correct
198 Correct 736 ms 636 KB Output is correct
199 Correct 688 ms 644 KB Output is correct
200 Correct 740 ms 692 KB Output is correct
201 Correct 687 ms 744 KB Output is correct
202 Correct 783 ms 744 KB Output is correct
203 Correct 716 ms 732 KB Output is correct
204 Correct 689 ms 600 KB Output is correct
205 Correct 777 ms 744 KB Output is correct
206 Correct 749 ms 544 KB Output is correct
207 Correct 708 ms 684 KB Output is correct
208 Correct 723 ms 800 KB Output is correct
209 Correct 819 ms 856 KB Output is correct
210 Correct 544 ms 532 KB Output is correct
211 Correct 560 ms 576 KB Output is correct
212 Correct 554 ms 748 KB Output is correct
213 Correct 538 ms 576 KB Output is correct
214 Correct 579 ms 752 KB Output is correct
215 Correct 594 ms 796 KB Output is correct
216 Correct 545 ms 892 KB Output is correct
217 Correct 533 ms 632 KB Output is correct
218 Correct 520 ms 544 KB Output is correct
219 Correct 531 ms 748 KB Output is correct
220 Correct 537 ms 600 KB Output is correct
221 Correct 555 ms 648 KB Output is correct
222 Correct 544 ms 652 KB Output is correct
223 Correct 566 ms 624 KB Output is correct
224 Correct 571 ms 536 KB Output is correct
225 Correct 552 ms 588 KB Output is correct
226 Correct 603 ms 652 KB Output is correct