QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232295#7635. Fairy Chessneko_nyaaWA 26ms3616kbC++233.5kb2023-10-30 09:38:052023-10-30 09:38:07

Judging History

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

  • [2023-10-30 09:38:07]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:3616kb
  • [2023-10-30 09:38:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

bool valid(int x, int y) {
	return (x >= 0 && y >= 0 && x < 8 && y < 8);
}

bitset<64> fill(bitset<64> bs, char c, int st) {
	int x = st/8, y = st%8;
	bs[st] = 1;
	// up down
	if (c == 'R' || c == 'Q' || c == 'C' || c == 'M') {
		for (int i = 0; i < 8; i++) {
			if (valid(x-i, y)) {int g = (x-i)*8 + y; bs[g] = 1;}
			if (valid(x+i, y)) {int g = (x+i)*8 + y; bs[g] = 1;}
			if (valid(x, y-1)) {int g = x*8 + (y-i); bs[g] = 1;}
			if (valid(x, y+1)) {int g = x*8 + (y+i); bs[g] = 1;}
		}
	}

	// diagonal
	if (c == 'B' || c == 'Q' || c == 'A' || c == 'M') {
		for (int i = 0; i < 8; i++) {
			if (valid(x-i, y-i)) {int g = (x-i)*8 + (y-i); bs[g] = 1;}
			if (valid(x+i, y-i)) {int g = (x+i)*8 + (y-i); bs[g] = 1;}
			if (valid(x-i, y+i)) {int g = (x-i)*8 + (y+i); bs[g] = 1;}
			if (valid(x+i, y+i)) {int g = (x+i)*8 + (y+i); bs[g] = 1;}
		}
	}

	// knight
	if (c == 'A' || c == 'C' || c == 'M') {
		if (valid(x-1, y-2)) {int g = (x-1)*8 + (y-2); bs[g] = 1;}
		if (valid(x+1, y-2)) {int g = (x+1)*8 + (y-2); bs[g] = 1;}
		if (valid(x-1, y+2)) {int g = (x-1)*8 + (y+2); bs[g] = 1;}
		if (valid(x+1, y+2)) {int g = (x+1)*8 + (y+2); bs[g] = 1;}
		if (valid(x-2, y-1)) {int g = (x-2)*8 + (y-1); bs[g] = 1;}
		if (valid(x+2, y-1)) {int g = (x+2)*8 + (y-1); bs[g] = 1;}
		if (valid(x-2, y+1)) {int g = (x-2)*8 + (y+1); bs[g] = 1;}
		if (valid(x+2, y+1)) {int g = (x+2)*8 + (y+1); bs[g] = 1;}
	}

	return bs;
}

bool check_attack(bitset<64> ps, char c, int st) {
	int x = st/8, y = st%8;

	// up down
	if (c == 'R' || c == 'Q' || c == 'C' || c == 'M') {
		for (int i = 0; i < 8; i++) {
			if (valid(x-i, y)) {int g = (x-i)*8 + y; if (ps[g] == 1) return 0;}
			if (valid(x+i, y)) {int g = (x+i)*8 + y; if (ps[g] == 1) return 0;}
			if (valid(x, y-1)) {int g = x*8 + (y-i); if (ps[g] == 1) return 0;}
			if (valid(x, y+1)) {int g = x*8 + (y+i); if (ps[g] == 1) return 0;}
		}
	}

	// diagonal
	if (c == 'B' || c == 'Q' || c == 'A' || c == 'M') {
		for (int i = 0; i < 8; i++) {
			if (valid(x-i, y-i)) {int g = (x-i)*8 + (y-i); if (ps[g] == 1) return 0;}
			if (valid(x+i, y-i)) {int g = (x+i)*8 + (y-i); if (ps[g] == 1) return 0;}
			if (valid(x-i, y+i)) {int g = (x-i)*8 + (y+i); if (ps[g] == 1) return 0;}
			if (valid(x+i, y+i)) {int g = (x+i)*8 + (y+i); if (ps[g] == 1) return 0;}
		}
	}

	// knight
	if (c == 'A' || c == 'C' || c == 'M') {
		if (valid(x-1, y-2)) {int g = (x-1)*8 + (y-2); if (ps[g] == 1) return 0;}
		if (valid(x+1, y-2)) {int g = (x+1)*8 + (y-2); if (ps[g] == 1) return 0;}
		if (valid(x-1, y+2)) {int g = (x-1)*8 + (y+2); if (ps[g] == 1) return 0;}
		if (valid(x+1, y+2)) {int g = (x+1)*8 + (y+2); if (ps[g] == 1) return 0;}
		if (valid(x-2, y-1)) {int g = (x-2)*8 + (y-1); if (ps[g] == 1) return 0;}
		if (valid(x+2, y-1)) {int g = (x+2)*8 + (y-1); if (ps[g] == 1) return 0;}
		if (valid(x-2, y+1)) {int g = (x-2)*8 + (y+1); if (ps[g] == 1) return 0;}
		if (valid(x+2, y+1)) {int g = (x+2)*8 + (y+1); if (ps[g] == 1) return 0;}
	}

	return 1;
}

bool go(string &s, int i, bitset<64> bs, bitset<64> ps) {
	if (i == 12) return 0;

	for (int j = 0; j < 64; j++) {
		if (!bs[j] && check_attack(ps, s[i], j)) {
			bitset<64> nx1 = fill(bs, s[i], j);
			bitset<64> nx2 = ps; nx2[j] = 1;
			if (!go(s, i+1, nx1, nx2)) {
				return 1;
			}
		}
	}
	return 0;
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	string s; cin >> s;
	bitset<64> bs;
	if (go(s, 0, bs, bs)) {
		cout << "Alice\n";
	} else {
		cout << "Bob\n";
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 26ms
memory: 3616kb

input:

BBAARRCCQQMM

output:

Bob

result:

ok single line: 'Bob'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

BAMBAMQQRCCR

output:

Alice

result:

ok single line: 'Alice'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

QQRAACMRMCBB

output:

Alice

result:

ok single line: 'Alice'

Test #4:

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

input:

MBBARQRMACQC

output:

Bob

result:

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