QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#175716#7180. Forward-Capturing Pawnsjsannemo#Compile Error//C++173.9kb2023-09-10 21:55:132023-09-10 21:55:14

Judging History

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

  • [2023-09-10 21:55:14]
  • 评测
  • [2023-09-10 21:55:13]
  • 提交

answer

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

#define rep(i,f,t) for (int i = f; i < t; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define trav(a,x) for (auto& a : x)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

struct Pos {
	bool white;
	int pr, pc, wr, wc, br, bc;

	int number() {
		int num = white;
		num = 8 * num + pr;
		num = 8 * num + pc;
		num = 8 * num + wr;
		num = 8 * num + wc;
		num = 8 * num + br;
		num = 8 * num + bc;
		return num;
	}

	void print() {
		cerr << (char)('a' + wc);
		cerr << 1 + wr << " ";
		cerr << (char)('a' + pc);
		cerr << 1 + pr << " ";
		cerr << (char)('a' + bc);
		cerr << 1 + br << " ";
		if (white) cout << "w" << endl;
		else cout << "b" << endl;
	}
};

bool won(const Pos& p) {
	return p.white && p.pr == 7;
}

bool in(int x) {
	return 0 <= x && x < 8;
}

bool valid(const Pos& p) {
	if (!in(p.pr) || !in(p.pc) || !in(p.wr) || !in(p.wc) || !in(p.br) || !in(p.bc)) return false;

	if (p.pr == p.wr && p.pc == p.wc) return false;
	if (p.pr == p.br && p.pc == p.bc) return false;
	if (abs(p.wr - p.br) <= 1 && abs(p.wc - p.bc) <= 1) return false;

	if (!p.white) return true;
	if (p.pr == 7 && (p.br == 7 || p.bc == p.pc)) return false;

	if (p.pc != p.bc) return true;
	if (p.br == p.pr + 1) return false;
	if (p.pr == 1 && p.br == 3) return false;
	return true;
}

vi dx = {-1, -1, -1, 0, 1, 1, 1, 0};
vi dy = {-1, 0, 1, 1, 1, 0, -1, -1};

vector<Pos> before(Pos p) {
	vector<Pos> res;
	if (!p.white) {
		Pos np = p;
		np.white = true;
		// white king
		rep(i,0,8) {
			np.wr = p.wr + dx[i];
			np.wc = p.wc + dy[i];
			if (valid(np)) res.push_back(np);
		}
		np = p;
		np.white = true;
		// white pawn
		np.pr = p.pr - 1;
		if (valid(np)) res.push_back(np);
		if (p.pr == 3 && !(p.wr == 2 && p.wc == p.pc)) {
			np.pr = p.pr - 2;
			if (valid(np)) res.push_back(np);
		}
	} else {
		Pos np = p;
		np.white = false;
		// black king
		rep(i,0,8) {
			np.br = p.br + dx[i];
			np.bc = p.bc + dy[i];
			if (valid(np)) res.push_back(np);
		}
	}
	return res;
}

vector<Pos> gen(Pos p) {
	vector<Pos> res;
	if (p.white) {
		Pos np = p;
		np.white = false;
		// white king
		rep(i,0,8) {
			np.wr = p.wr + dx[i];
			np.wc = p.wc + dy[i];
			if (valid(np)) res.push_back(np);
		}
		np = p;
		np.white = true;
		// white pawn
		np.pr = p.pr + 1;
		if (valid(np)) res.push_back(np);
		if (p.pr == 1 && !(p.wr == 2 && p.wc == p.pc)) {
			np.pr = p.pr - 2;
			if (valid(np)) res.push_back(np);
		}
	} else {
		Pos np = p;
		np.white = true;
		// black king
		rep(i,0,8) {
			np.br = p.br + dx[i];
			np.bc = p.bc + dy[i];
			if (valid(np)) res.push_back(np);
		}
	}
	return res;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int M = 2 * 8 * 8 * 8 * 8 * 8 * 8;
	vector<bool> whitewin(M);
	queue<Pos> p;

	rep(pc,0,8) {
		rep(wr,0,8)
		rep(wc,0,8)
		rep(br,0,8)
		rep(bc,0,8) {
			Pos pos {true, 7, pc, wr, wc, br, bc};
			if (!valid(pos)) continue;
			whitewin[pos.number()] = true;
			p.push(pos);
		}
	}

	while (!p.empty()) {
		Pos nx = p.front(); p.pop();
		//cerr << "win" << endl;
		if (!nx.white) {
			vector<Pos> b = before(nx);
			for (Pos& pos : b) {
				int num = pos.number();
				if (!whitewin[num]) {
					whitewin[num] = true;
					p.push(pos);
				}
			}
		} else {
			vector<Pos> b = before(nx);
			for (Pos& pos : b) {
				//pos.print();
				int num = pos.number();
				vector<Pos> opt = gen(pos);
				for (Pos& o : opt) {
					int onum = o.number();
					if (!whitewin[onum]) {
						//cerr << "saving pos:" << endl;
						//o.print();
						goto nowin;
					}
				}
				whitewin[num] = true;
				p.push(pos);
nowin:;
			}
		}
		//cerr << endl;
	}

	int N;
	cin >> N;
	rep(i,0,N) {
		string w, p, b, pl;
		cin >> w >> p >> b >> pl;
		Pos pos;
		if (pl == "w") pos.white = true;
		pos.wr = w[1] - '1';
		pos.br = b[1] - '1';
		pos.pr = p[1] - '1';
		pos.wc = w[0] - 'a';
		pos.bc = b[0] - 'a';
		pos.pc = p[0] - 'a';
		if (whitewin[pos.number()]) cout << "Win" << endl;
		else cout << "Draw" << endl;
	}
}
0

詳細信息

answer.code:202:1: error: expected unqualified-id before numeric constant
  202 | 0
      | ^