QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21349 | #2821. 鸭棋 | glory_to_the_qy# | AC ✓ | 4ms | 3664kb | C++20 | 4.0kb | 2022-03-04 16:33:20 | 2022-05-08 02:55:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct piece {
int side, type;
piece(int side = -1, int type = -1) : side(side), type(type) {
}
} board[10][9];
/*
* captain: 1
* guard: 2
* elephant: 3
* horse: 4
* car: 5
* duck: 6
* soldier: 7
*/
void init_board() {
auto set = [&](int i, int j, int v) {
board[i][j] = board[i][8 - j] = piece(0, v);
board[9 - i][j] = board[9 - i][8 - j] = piece(1, v);
};
set(0, 0, 5);
set(0, 1, 4);
set(0, 2, 3);
set(0, 3, 2);
set(0, 4, 1);
set(2, 0, 6);
set(3, 0, 7);
set(3, 2, 7);
set(3, 4, 7);
}
string get_piece(int i, int j) {
int player = board[i][j].side;
int type = board[i][j].type;
if (player == -1)
return "NA";
string ret = "";
if (player == 0) ret = "red";
else if (player == 1) ret = "blue";
else throw;
ret += " ";
if (type == 1) ret += "captain";
else if (type == 2) ret += "guard";
else if (type == 3) ret += "elephant";
else if (type == 4) ret += "horse";
else if (type == 5) ret += "car";
else if (type == 6) ret += "duck";
else if (type == 7) ret += "soldier";
else throw;
return ret;
}
bool checkmate;
bool empty(int x, int y) {
return board[x][y].side == -1;
}
bool outside(int x, int y) {
return x < 0 || y < 0 || x > 9 || y > 8;
}
bool go(int xs, int ys, int xt, int yt) {
int type = board[xs][ys].type;
auto is = [&](int x, int y) {
return x == xt && y == yt;
};
if (board[xs][ys].side == board[xt][yt].side)
return false;
if (empty(xs, ys)) return false;
if (type == 1) {
for (int d : {-1, 1})
if (is(xs + d, ys) || is(xs, ys + d))
return true;
}
else if (type == 2) {
for (int a : {-1, 1})
for (int b : {-1, 1})
if (is(xs + a, ys + b))
return true;
}
else if (type == 3) {
for (int a : {-1, 1})
for (int b : {-1, 1})
if (is(xs + 2 * a, ys + 2 * b) && empty(xs + a, ys + b))
return true;
}
else if (type == 4) {
for (int a : {-1, 1})
for (int b : {-1, 1}) {
if (is(xs + 2 * a, ys + b) && empty(xs + a, ys)) {
return true;
}
if (is(xs + a, ys + 2 * b) && empty(xs, ys + b)) {
return true;
}
}
}
else if (type == 5) {
if (xs != xt && ys != yt) return false;
if (xs > xt) swap(xs, xt);
if (ys > yt) swap(ys, yt);
for (int i = xs; i <= xt; ++i)
for (int j = ys; j <= yt; ++j)
if (!empty(i, j) && !((i == xs && j == ys) || (i == xt && j == yt))) {
return false;
}
return true;
}
else if (type == 6) {
for (int a : {-1, 1})
for (int b : {-1, 1}) {
if (is(xs + 3 * a, ys + 2 * b) && empty(xs + a + a, ys + b) && empty(xs + a, ys))
return true;
if (is(xs + 2 * a, ys + 3 * b) && empty(xs, ys + b) && empty(xs + a, ys + b + b))
return true;
}
}
else if (type == 7) {
for (int a : {-1, 0, 1})
for (int b : {-1, 0, 1})
if (a != 0 || b != 0)
if (is(xs + a, ys + b))
return true;
}
else {
throw;
}
return false;
}
bool if_check() {
for (int xt = 0; xt <= 9; ++xt)
for (int yt = 0; yt <= 8; ++yt) {
if (board[xt][yt].type == 1) {
for (int xs = 0; xs <= 9; ++xs)
for (int ys = 0; ys <= 8; ++ys)
if (xs != xt || ys != yt) {
if (go(xs, ys, xt, yt)) {
return true;
}
}
}
}
return false;
}
int main() {
init_board();
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int Q;
cin >> Q;
int cur_side = 0;
while (Q--) {
int xs, ys, xt, yt;
cin >> xs >> ys >> xt >> yt;
string start_name = get_piece(xs, ys);
string end_name = get_piece(xt, yt);
if (board[xs][ys].side != cur_side || checkmate || !go(xs, ys, xt, yt)) {
cout << "Invalid command" << '\n';
}
else {
if (board[xt][yt].type == 1) {
checkmate = true;
}
board[xt][yt] = board[xs][ys];
board[xs][ys] = piece();
string third = (!checkmate && if_check()) ? "yes" : "no";
string forth = checkmate ? "yes" : "no";
cout << start_name << ";" << end_name << ";" << third << ";" << forth << '\n';
cur_side ^= 1;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3664kb
input:
18 0 0 7 0 9 0 8 0 0 1 1 3 0 2 2 0 0 3 1 2 0 4 0 3 9 4 8 4 3 2 2 3 7 0 4 2 7 0 5 3 9 2 7 4 2 0 4 3 9 1 8 3 4 3 6 6 7 4 9 2 8 4 9 4 6 6 9 4 9 8 8 8
output:
Invalid command Invalid command Invalid command Invalid command red guard;NA;no;no Invalid command blue captain;NA;no;no red soldier;NA;no;no Invalid command Invalid command blue elephant;NA;no;no red duck;NA;no;no blue horse;NA;no;no red duck;blue soldier;no;no Invalid command blue captain;NA;yes;n...
result:
ok 18 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
1000 0 7 2 6 3 8 4 8 3 0 4 0 0 6 8 6 0 3 1 4 6 2 5 3 6 0 5 0 0 4 1 4 9 7 7 6 9 5 8 4 9 5 8 6 7 0 3 2 3 0 2 1 9 2 7 4 5 3 4 2 1 4 2 4 0 1 2 2 6 0 7 1 9 5 8 4 2 6 1 4 2 1 1 2 2 8 8 1 9 8 8 8 6 6 7 7 7 4 9 2 8 8 8 0 2 0 5 2 2 8 6 1 1 7 1 1 0 3 1 2 3 8 3 7 9 0 8 0 0 3 1 2 3 4 2 5 9 6 9 4 6 4 5 5 4 2 7 4...
output:
red horse;NA;no;no Invalid command Invalid command Invalid command Invalid command blue soldier;NA;no;no Invalid command red captain;NA;no;no blue horse;NA;no;no Invalid command Invalid command Invalid command red soldier;NA;no;no blue elephant;NA;no;no Invalid command red captain;NA;no;no Invalid c...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 4ms
memory: 3584kb
input:
1000 3 8 4 1 6 2 8 2 0 0 1 5 9 7 7 6 0 7 8 7 9 5 8 6 5 4 1 0 9 7 6 4 9 7 0 3 2 0 3 0 9 3 8 0 2 8 9 2 7 5 7 8 9 5 8 6 9 6 8 2 6 2 6 3 0 7 1 7 9 1 7 2 1 7 0 5 7 0 8 5 9 5 0 4 3 4 4 5 0 6 8 8 6 2 5 1 9 5 8 4 0 1 2 1 0 3 2 4 2 7 8 5 9 8 8 8 0 0 1 0 3 2 7 3 3 0 0 1 0 5 9 4 9 2 7 4 0 1 2 2 9 7 1 0 6 6 6 5...
output:
Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid comm...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
1000 6 4 5 5 9 1 4 5 9 7 5 8 9 4 8 4 0 6 5 1 0 3 5 5 0 3 5 5 9 7 6 2 2 8 9 6 9 5 5 8 0 4 1 4 0 0 5 6 0 7 3 5 2 8 7 8 0 5 6 8 7 8 9 8 9 2 9 3 0 3 1 2 3 2 5 5 0 5 1 6 3 6 5 6 3 2 1 1 0 5 6 7 9 5 3 4 3 0 2 4 3 4 6 3 9 7 8 7 0 6 9 1 6 8 8 4 6 8 6 3 6 0 5 7 2 0 8 7 9 8 4 0 0 7 3 8 0 3 5 2 2 0 1 7 3 2 0 3...
output:
Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command red captain;NA;no;no Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid command Invalid...
result:
ok 1000 lines