제출 #1338179

#제출 시각아이디문제언어결과실행 시간메모리
1338179limits죄수들의 도전 (IOI22_prison)C++20
65 / 100
7 ms1092 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue

template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<vi>;
using vvi = V<vi>;

#include "prison.h"

const int LG = 15;
const int P = 4782969;

std::vector<std::vector<int>> devise_strategy(int N) {
	V<vi> mat(1, vi(N+1));

	mat[0][0] = 0;
	int p = 1;
	while (p*3 < N) p*=3;
	fnr(i, 1, N+1) mat[0][i] = (i-1)/p % 3 + 1;

	int j = 1, t = 1;

	while (p > 0) {
		int nx = p/3;
		mat.pb(vi(N+1));
		mat.pb(vi(N+1));
		mat.pb(vi(N+1));

		mat[j][0] = mat[j+1][0] = mat[j+2][0] = t;

		fnr(i, 1, N+1) {
			int d = (i-1) / p % 3;
			f0r(k, 3) {
				if (d < k) mat[j+k][i] = !t ? -1 : -2;
				else if (d > k) mat[j+k][i] = !t ? -2 : -1;
				else {
					if (!nx) mat[j+k][i] = 0;
					else mat[j+k][i] = (j+3) + ((i-1)/nx % 3);
				}
			}
		}
		p = nx;
		j += 3;
		t ^= 1;
	}

	return mat;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...