제출 #635447

#제출 시각아이디문제언어결과실행 시간메모리
635447marvinthang죄수들의 도전 (IOI22_prison)C++17
0 / 100
1 ms212 KiB
/*************************************
*    author: marvinthang             *
*    created: 25.08.2022 20:38:19    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                 div  ___div
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define             FULL(i)  (MASK(i) - 1)
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }

template <class T>             scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class T>            print_op(vector <T>)  { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; }
template <class U, class V>   scan_op(pair <U, V>)  { return in >> u.fi >> u.se; }
template <class U, class V>  print_op(pair <U, V>)  { return out << '(' << u.fi << ", " << u.se << ')'; }

const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0);
const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2};
int from[22], to[22];

void solve(int state, int level, vector <vector <int>> &res) {
	int l = from[state], r = to[state];
	int cur = level & 1;
	int pre = cur ^ 1;
	res[state][0] = cur;
	res[state][l++] = -1 - cur;
	res[state][r--] = -1 - pre;
	int len = r - l + 1;
	if (len <= 1) return;
	vector <int> child;
	if (len <= 4) {
		int m = min(r, l + 1);

		from[level * 3 + 1] = l; to[level * 3 + 2] = m;
		from[level * 3 + 2] = m + 1; to[level * 3 + 2] = r;

		child.push_back(level * 3 + 1);
		if (len > 2) child.push_back(level * 3 + 2);
	} else {
		int mlr = (len + 2) / 3;
		int m1 = l + mlr - 1;
		int m2 = m1 + mlr;

		from[level * 3 + 1] = l; to[level * 3 + 1] = m1;
		from[level * 3 + 2] = m1 + 1; to[level * 3 + 2] = m2;
		from[level * 3 + 3] = m2 + 1; to[level * 3 + 3] = r;

		child.push_back(level * 3 + 1);
		child.push_back(level * 3 + 2);
		child.push_back(level * 3 + 3);
	}
	for (int cur_state: child) {
		for (int i = from[cur_state]; i <= to[cur_state]; ++i) res[state][i] = cur_state;
		res[cur_state][l - 1] = -1 - pre;
		res[cur_state][r + 1] = -1 - cur;
		for (int pre_state: child) if (pre_state != cur_state) {
			for (int i = from[pre_state]; i <= to[pre_state]; ++i) 
				res[cur_state][i] = -1 - (pre_state < cur_state ? cur : pre);
		}
		solve(cur_state, level + 1, res);
	}
}

vector <vector <int>> devise_strategy(int n) {
	vector <vector <int>> res(21, vector<int> (n + 1, 0));

	from[0] = 1; to[0] = n;
	solve(0, 0, res);
	return res;
}

// vector <vector <int>> res;
// int n, a, b;

// int main(void) {
// 	ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
// 	file("ioi22_day1_prison");
// 	cin >> n >> a >> b;
// 	// for (int i = NUM_BIT; i--; ) cout << get_bit(a, i);
// 	// cout << '\n';
// 	// for (int i = NUM_BIT; i--; ) cout << get_bit(b, i);
// 	// cout << '\n';
// 	// // cout << bitset<13>(a) << '\n' << bitset<13>(b) << '\n';
// 	res = devise_strategy(n);
// 	// // for (int i = 0; i < NUM_STATE; ++i) {
// 	// // 	cout << decode(i) << ": ";
// 	// // 	cout << res[i][0] << ' ';
// 	// // 	for (int j = 1; j <= n; ++j) 
// 	// // 		if (res[i][j] >= 0) cout << decode(res[i][j]) << ' '; else cout << res[i][j] << ' ';
// 	// // 	cout << '\n';
// 	// // }
// 	// Try(0);
// 	cerr << "Time elapsed: " << TIME << " s.\n";
// 	return (0^0);
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...