답안 #895557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895557 2023-12-30T09:00:13 Z marvinthang Navigation 2 (JOI21_navigation2) C++17
100 / 100
534 ms 2584 KB
/*************************************
*    author: marvinthang             *
*    created: 30.12.2023 10:47:39    *
*************************************/

#include "Anna.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 << '}'; }

// end of template

void Anna(int N, int K, vector <int> R, vector <int> C) {
	auto get_idx = [&] (int x, int y, int i) {
		x -= R[i]; y -= C[i];
		if (y < -1) return 2;
		if (y > +1) return 3;
		if (x < -1) return 4;
		if (x > +1) return 5;
		++x; ++y;
		return x * 3 + y + 6;
	};
	vector <vector <int>> board(N, vector<int>(N));
	auto check = [&] (int pos) {
		int px = pos / 3, py = pos % 3;
		REP(x, N) REP(y, N) {
			int id = (x + px) % 3 * 3 + (y + py) % 3;
			if (id < K) {
				board[x][y] = get_idx(x, y, id);
				if (board[x][y] == 14) return false;
			} else if (id == K) board[x][y] = -1;
			else board[x][y] = 1;
		}
		return true;
	};
	REP(pos, 9) if (check(pos)) {
		vector <bool> used(14);
		REP(i, N) REP(j, N) if (board[i][j] >= 0) used[board[i][j]] = true;
		int mi = find(1 + ALL(used), false) - used.begin();
		REP(i, N) REP(j, N) {
			if (board[i][j] == -1) board[i][j] = mi - 1;
			else if (board[i][j] > mi) --board[i][j];
			SetFlag(i, j, board[i][j]);
		}
		return;
	}
}
/*************************************
*    author: marvinthang             *
*    created: 30.12.2023 11:08:47    *
*************************************/

#include "Bruno.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 << '}'; }

// end of template


vector <int> Bruno(int K, vector <int> value) {
	int pos = find(ALL(value), 1) - value.begin();
	int nxt = pos / 3 * 3 + (pos % 3 + 1) % 3;
	if (value[nxt] == 1) pos = nxt;
	int px = (pos / 3 + 1) % 3, py = (pos % 3 + 1) % 3;
	int mi = -1;
	REP(i, 9) {
		int x = (i / 3 - px + 3) % 3, y = (i % 3 - py + 3) % 3;
		int id = x * 3 + y;
		if (id == K) mi = value[i];
	}
	REP(i, 9) if (value[i] > mi) ++value[i];
	vector <int> res(K);
	REP(i, 9) {
		int x = (i / 3 - px + 3) % 3, y = (i % 3 - py + 3) % 3;
		int id = x * 3 + y;
		if (id < K) {
			if (value[i] < 6) res[id] = value[i] - 2;
			else {
				x = value[i] / 3 - i / 3 - 2; y = value[i] % 3 - i % 3;
				if (y) res[id] = y > 0;
				else if (x) res[id] = 2 + (x > 0);
				else res[id] = 4;
			}
		}
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 920 KB Output is correct
2 Correct 8 ms 920 KB Output is correct
3 Correct 9 ms 920 KB Output is correct
4 Correct 9 ms 732 KB Output is correct
5 Correct 9 ms 920 KB Output is correct
6 Correct 9 ms 664 KB Output is correct
7 Correct 9 ms 664 KB Output is correct
8 Correct 9 ms 996 KB Output is correct
9 Correct 7 ms 664 KB Output is correct
10 Correct 8 ms 920 KB Output is correct
11 Correct 9 ms 920 KB Output is correct
12 Correct 9 ms 920 KB Output is correct
13 Correct 9 ms 920 KB Output is correct
14 Correct 8 ms 664 KB Output is correct
15 Correct 9 ms 920 KB Output is correct
16 Correct 9 ms 664 KB Output is correct
17 Correct 6 ms 1172 KB Output is correct
18 Correct 9 ms 664 KB Output is correct
19 Correct 8 ms 664 KB Output is correct
20 Correct 8 ms 920 KB Output is correct
21 Correct 9 ms 920 KB Output is correct
22 Correct 9 ms 664 KB Output is correct
23 Correct 9 ms 664 KB Output is correct
24 Correct 10 ms 1092 KB Output is correct
25 Correct 9 ms 920 KB Output is correct
26 Correct 7 ms 920 KB Output is correct
27 Correct 7 ms 664 KB Output is correct
28 Correct 8 ms 680 KB Output is correct
29 Correct 9 ms 920 KB Output is correct
30 Correct 9 ms 920 KB Output is correct
31 Correct 9 ms 664 KB Output is correct
32 Correct 10 ms 920 KB Output is correct
33 Correct 10 ms 920 KB Output is correct
34 Correct 9 ms 832 KB Output is correct
35 Correct 9 ms 664 KB Output is correct
36 Correct 10 ms 920 KB Output is correct
37 Correct 8 ms 664 KB Output is correct
38 Correct 8 ms 920 KB Output is correct
39 Correct 10 ms 1088 KB Output is correct
40 Correct 10 ms 920 KB Output is correct
41 Correct 10 ms 920 KB Output is correct
42 Correct 9 ms 672 KB Output is correct
43 Correct 10 ms 664 KB Output is correct
44 Correct 9 ms 752 KB Output is correct
45 Correct 8 ms 1088 KB Output is correct
46 Correct 11 ms 920 KB Output is correct
47 Correct 10 ms 664 KB Output is correct
48 Correct 10 ms 832 KB Output is correct
49 Correct 10 ms 664 KB Output is correct
50 Correct 9 ms 920 KB Output is correct
51 Correct 11 ms 664 KB Output is correct
52 Correct 12 ms 920 KB Output is correct
53 Correct 10 ms 916 KB Output is correct
54 Correct 10 ms 664 KB Output is correct
55 Correct 9 ms 664 KB Output is correct
56 Correct 13 ms 920 KB Output is correct
57 Correct 13 ms 920 KB Output is correct
58 Correct 11 ms 916 KB Output is correct
59 Correct 10 ms 664 KB Output is correct
60 Correct 10 ms 664 KB Output is correct
61 Correct 11 ms 920 KB Output is correct
62 Correct 13 ms 664 KB Output is correct
63 Correct 15 ms 1096 KB Output is correct
64 Correct 13 ms 920 KB Output is correct
65 Correct 13 ms 920 KB Output is correct
66 Correct 12 ms 920 KB Output is correct
67 Correct 11 ms 920 KB Output is correct
68 Correct 11 ms 920 KB Output is correct
69 Correct 10 ms 664 KB Output is correct
70 Correct 12 ms 920 KB Output is correct
71 Correct 13 ms 920 KB Output is correct
72 Correct 12 ms 920 KB Output is correct
73 Correct 13 ms 664 KB Output is correct
74 Correct 12 ms 664 KB Output is correct
75 Correct 10 ms 668 KB Output is correct
76 Correct 13 ms 664 KB Output is correct
77 Correct 13 ms 1088 KB Output is correct
78 Correct 11 ms 920 KB Output is correct
79 Correct 15 ms 920 KB Output is correct
80 Correct 12 ms 684 KB Output is correct
81 Correct 14 ms 920 KB Output is correct
82 Correct 12 ms 916 KB Output is correct
83 Correct 15 ms 920 KB Output is correct
84 Correct 11 ms 920 KB Output is correct
85 Correct 12 ms 732 KB Output is correct
86 Correct 11 ms 920 KB Output is correct
87 Correct 13 ms 664 KB Output is correct
88 Correct 13 ms 664 KB Output is correct
89 Correct 13 ms 920 KB Output is correct
90 Correct 13 ms 920 KB Output is correct
91 Correct 11 ms 920 KB Output is correct
92 Correct 12 ms 920 KB Output is correct
93 Correct 12 ms 920 KB Output is correct
94 Correct 12 ms 920 KB Output is correct
95 Correct 12 ms 920 KB Output is correct
96 Correct 15 ms 672 KB Output is correct
97 Correct 11 ms 864 KB Output is correct
98 Correct 12 ms 664 KB Output is correct
99 Correct 13 ms 920 KB Output is correct
100 Correct 12 ms 684 KB Output is correct
101 Correct 13 ms 664 KB Output is correct
102 Correct 11 ms 676 KB Output is correct
103 Correct 11 ms 752 KB Output is correct
104 Correct 12 ms 664 KB Output is correct
105 Correct 12 ms 664 KB Output is correct
106 Correct 13 ms 920 KB Output is correct
107 Correct 13 ms 920 KB Output is correct
108 Correct 15 ms 672 KB Output is correct
109 Correct 12 ms 664 KB Output is correct
110 Correct 13 ms 664 KB Output is correct
111 Correct 11 ms 664 KB Output is correct
112 Correct 11 ms 664 KB Output is correct
113 Correct 10 ms 920 KB Output is correct
114 Correct 10 ms 832 KB Output is correct
115 Correct 15 ms 1104 KB Output is correct
116 Correct 12 ms 920 KB Output is correct
117 Correct 10 ms 664 KB Output is correct
118 Correct 12 ms 664 KB Output is correct
119 Correct 12 ms 920 KB Output is correct
120 Correct 491 ms 1728 KB Output is correct
121 Correct 506 ms 1772 KB Output is correct
122 Correct 480 ms 1944 KB Output is correct
123 Correct 527 ms 1664 KB Output is correct
124 Correct 501 ms 1576 KB Output is correct
125 Correct 515 ms 1772 KB Output is correct
126 Correct 498 ms 1664 KB Output is correct
127 Correct 532 ms 1232 KB Output is correct
128 Correct 506 ms 1604 KB Output is correct
129 Correct 534 ms 1916 KB Output is correct
130 Correct 499 ms 1984 KB Output is correct
131 Correct 479 ms 1864 KB Output is correct
132 Correct 513 ms 1804 KB Output is correct
133 Correct 514 ms 1712 KB Output is correct
134 Correct 491 ms 1448 KB Output is correct
135 Correct 502 ms 1776 KB Output is correct
136 Correct 487 ms 1916 KB Output is correct
137 Correct 495 ms 1656 KB Output is correct
138 Correct 498 ms 1496 KB Output is correct
139 Correct 490 ms 1752 KB Output is correct
140 Correct 488 ms 1632 KB Output is correct
141 Correct 492 ms 1756 KB Output is correct
142 Correct 458 ms 1616 KB Output is correct
143 Correct 494 ms 1892 KB Output is correct
144 Correct 450 ms 1320 KB Output is correct
145 Correct 515 ms 1692 KB Output is correct
146 Correct 444 ms 2480 KB Output is correct
147 Correct 428 ms 1604 KB Output is correct
148 Correct 469 ms 2204 KB Output is correct
149 Correct 431 ms 2464 KB Output is correct
150 Correct 425 ms 2052 KB Output is correct
151 Correct 443 ms 1900 KB Output is correct
152 Correct 455 ms 2156 KB Output is correct
153 Correct 513 ms 1704 KB Output is correct
154 Correct 468 ms 1836 KB Output is correct
155 Correct 456 ms 1448 KB Output is correct
156 Correct 484 ms 2056 KB Output is correct
157 Correct 434 ms 2180 KB Output is correct
158 Correct 478 ms 1380 KB Output is correct
159 Correct 456 ms 2048 KB Output is correct
160 Correct 493 ms 1592 KB Output is correct
161 Correct 496 ms 1820 KB Output is correct
162 Correct 468 ms 2332 KB Output is correct
163 Correct 471 ms 2584 KB Output is correct
164 Correct 424 ms 1840 KB Output is correct
165 Correct 442 ms 2528 KB Output is correct
166 Correct 427 ms 1924 KB Output is correct
167 Correct 425 ms 2140 KB Output is correct
168 Correct 465 ms 1776 KB Output is correct
169 Correct 439 ms 2284 KB Output is correct
170 Correct 452 ms 1848 KB Output is correct
171 Correct 467 ms 1572 KB Output is correct
172 Correct 450 ms 2220 KB Output is correct
173 Correct 422 ms 1860 KB Output is correct
174 Correct 421 ms 1804 KB Output is correct
175 Correct 441 ms 1864 KB Output is correct
176 Correct 431 ms 2100 KB Output is correct
177 Correct 423 ms 1848 KB Output is correct
178 Correct 422 ms 1612 KB Output is correct
179 Correct 432 ms 1808 KB Output is correct
180 Correct 435 ms 2016 KB Output is correct
181 Correct 430 ms 2244 KB Output is correct
182 Correct 438 ms 1760 KB Output is correct
183 Correct 437 ms 1900 KB Output is correct
184 Correct 455 ms 2152 KB Output is correct
185 Correct 445 ms 1876 KB Output is correct
186 Correct 429 ms 1860 KB Output is correct
187 Correct 482 ms 2252 KB Output is correct
188 Correct 525 ms 1908 KB Output is correct
189 Correct 454 ms 1776 KB Output is correct
190 Correct 443 ms 1576 KB Output is correct
191 Correct 497 ms 2056 KB Output is correct
192 Correct 421 ms 1860 KB Output is correct
193 Correct 449 ms 2268 KB Output is correct
194 Correct 426 ms 1872 KB Output is correct
195 Correct 429 ms 2072 KB Output is correct
196 Correct 435 ms 2172 KB Output is correct
197 Correct 463 ms 1944 KB Output is correct
198 Correct 530 ms 1756 KB Output is correct
199 Correct 427 ms 1696 KB Output is correct
200 Correct 443 ms 1588 KB Output is correct
201 Correct 425 ms 1704 KB Output is correct
202 Correct 432 ms 1800 KB Output is correct
203 Correct 436 ms 1460 KB Output is correct
204 Correct 455 ms 2240 KB Output is correct
205 Correct 441 ms 1896 KB Output is correct
206 Correct 422 ms 1968 KB Output is correct
207 Correct 425 ms 2280 KB Output is correct
208 Correct 470 ms 1836 KB Output is correct
209 Correct 420 ms 1668 KB Output is correct
210 Correct 326 ms 2188 KB Output is correct
211 Correct 319 ms 1680 KB Output is correct
212 Correct 377 ms 1712 KB Output is correct
213 Correct 351 ms 1736 KB Output is correct
214 Correct 320 ms 1956 KB Output is correct
215 Correct 357 ms 1636 KB Output is correct
216 Correct 341 ms 1648 KB Output is correct
217 Correct 341 ms 1676 KB Output is correct
218 Correct 328 ms 1288 KB Output is correct
219 Correct 387 ms 1660 KB Output is correct
220 Correct 335 ms 1776 KB Output is correct
221 Correct 327 ms 1780 KB Output is correct
222 Correct 325 ms 1968 KB Output is correct
223 Correct 325 ms 2012 KB Output is correct
224 Correct 336 ms 1532 KB Output is correct
225 Correct 363 ms 1792 KB Output is correct
226 Correct 349 ms 1844 KB Output is correct