QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#230883#7635. Fairy Chessucup-team2112#WA 682ms34508kbC++174.4kb2023-10-28 21:38:202023-10-28 21:38:20

Judging History

你现在查看的是最新测评结果

  • [2023-10-28 21:38:20]
  • 评测
  • 测评结果:WA
  • 用时:682ms
  • 内存:34508kb
  • [2023-10-28 21:38:20]
  • 提交

answer

#include "bits/stdc++.h"
#define rep(i, a, n) for (auto i = a; i <= (n); ++i)
#define revrep(i, a, n) for (auto i = n; i >= (a); --i)
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a).size()
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;

template<class A, class B> string to_string(const pair<A, B> &p);
template<class A, class B, class C> string to_string(const tuple<A, B, C> &p);
template<class A, class B, class C, class D> string to_string(const tuple<A, B, C, D> &p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string) s); }
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(bool x) { return x ? "true" : "false"; }
template<class A, class T = typename A::value_type> string to_string(const A &v) {
	bool first = 1;
	string res = "{";
	for (const auto &x: v) {
		if (!first) res += ", ";
		first = 0;
		res += to_string(x);
	}
	res += "}";
	return res;
}
template<class A, class B> string to_string(const pair<A, B> &p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<class A, class B, class C> string to_string(const tuple<A, B, C> &p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template<class A, class B, class C, class D> string to_string(const tuple<A, B, C, D> &p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
template<class H, class... T> void debug_out(const H& h, const T&... t) {
	cerr << " " << to_string(h);
	debug_out(t...);
}
#ifndef ONLINE_JUDGE
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
	#define debug(...) if (0) puts("No effect.")
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	using ull = unsigned long long;

	vector masks(7, vector(64, 0));

	auto get_knight = [](int i, int j) {
		static const vector<pii> ds{{1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}};
		ull msk = 1ull << (i * 8 + j);
		for (auto [di, dj] : ds) {
			int ni = i + di;
			int nj = j + dj;
			if (ni >= 0 && ni < 8 && nj >= 0 && nj < 8) {
				msk |= 1ull << (ni * 8 + nj);
			}
		}
		return msk;
	};
	auto get_bishop = [](int x, int y) {
		ull msk = 0;
		rep(i, 0, 7) rep(j, 0, 7) {
			if (i - j == x - y || i + j == x + y) {
				msk |= 1ull << (i * 8 + j);
			}
		}
		return msk;
	};
	auto get_rook = [](int x, int y) {
		ull msk = 0;
		rep(i, 0, 7) rep(j, 0, 7) {
			if (i == x || j == y) {
				msk |= 1ull << (i * 8 + j);
			}
		}
		return msk;
	};
	
	rep(i, 0, 7) rep(j, 0, 7) masks[0][i * 8 + j] = get_knight(i, j);
	rep(i, 0, 7) rep(j, 0, 7) masks[1][i * 8 + j] = get_bishop(i, j);
	rep(i, 0, 7) rep(j, 0, 7) masks[2][i * 8 + j] = get_rook(i, j);
	rep(i, 0, 7) rep(j, 0, 7) masks[3][i * 8 + j] = masks[1][i * 8 + j] | masks[2][i * 8 + j];
	rep(i, 0, 7) rep(j, 0, 7) masks[4][i * 8 + j] = masks[0][i * 8 + j] | masks[1][i * 8 + j];
	rep(i, 0, 7) rep(j, 0, 7) masks[5][i * 8 + j] = masks[0][i * 8 + j] | masks[2][i * 8 + j];
	rep(i, 0, 7) rep(j, 0, 7) masks[6][i * 8 + j] = masks[0][i * 8 + j] | masks[3][i * 8 + j];

	string moves; cin >> moves;
	vector<int> as(12);
	rep(i, 0, 11) {
		int c = moves[i];
		if (c == 'B') as[i] = 1;
		else if (c == 'R') as[i] = 2;
		else if (c == 'Q') as[i] = 3;
		else if (c == 'A') as[i] = 4;
		else if (c == 'C') as[i] = 5;
		else if (c == 'M') as[i] = 6;
		else assert(0);
	}

	map<pair<int, ull>, int> dp;
	auto dfs = [&](auto &dfs, int dep, ull now_msk) -> int {
		if (dep == 12) {
			return 0;
		}
		if (dp.count(make_pair(dep, now_msk)) > 0) {
			return dp[make_pair(dep, now_msk)];
		}
		int res = 0;
		int c = as[dep];
		for (ull x = now_msk; x; x -= x & -x) {
			int d = __builtin_ctzll(x);
			int t = dfs(dfs, dep + 1, now_msk & (~masks[c][d]));
			if (t == 0) {
				res = 1;
				break;
			}
		}
		return dp[make_pair(dep, now_msk)] = res;
	};
	int res = dfs(dfs, 0, ~ull{});
	puts(res ? "Alice" : "Bob");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 682ms
memory: 34508kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 33ms
memory: 6132kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: 0
Accepted
time: 4ms
memory: 4284kb

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

score: -100
Wrong Answer
time: 18ms
memory: 5304kb

input:

MBBARQRMACQC

output:

Bob

result:

wrong answer 1st lines differ - expected: 'Alice', found: 'Bob'