QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72036 | #2821. 鸭棋 | Cyh29hao | AC ✓ | 3ms | 3520kb | C++14 | 4.2kb | 2023-01-13 18:38:48 | 2023-01-13 18:38:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mx=8;
int Q,xs,ys,xt,yt;
int king[2][2]={{0,4},{9,4}};
bool flag=0,opt=0;
const string name[mx]={"NA","captain","guard","elephant","horse","car","duck","soldier"};
const string col[2]={"red ","blue "};
const string ok[2]={"no","yes"};
struct node{
int pos;
int clr;//0red 1blue
}mp[10][9];
inline int abs(int x)
{
return x>0?x:-x;
}
inline void pre(int x,int y,int pos)
{
mp[x][y]=mp[x][8-y]=node{pos,0};
mp[9-x][8-y]=mp[9-x][y]=node{pos,1};
}
inline int max(int a,int b)
{
return a>b?a:b;
}
inline int min(int a,int b)
{
return a<b?a:b;
}
inline bool check(int chc=1)
{
if(xs<0 || xs>9 || ys<0 || ys>8 || xt<0 || xt>9 || yt<0 || yt>8)return 0;
if(xs==xt && ys==yt)return 0;
if(!mp[xs][ys].pos || flag)return 0;
if(chc && mp[xs][ys].clr!=opt)return 0;
if(mp[xt][yt].pos && mp[xs][ys].clr==mp[xt][yt].clr)return 0;
int dx=xt-xs,dy=yt-ys,adx=abs(dx),ady=abs(dy);
//cout<<dx<<' '<<dy<<' '<<endl;
switch(mp[xs][ys].pos)
{
case 1:{
if(!((adx==0 && ady==1) || (adx==1 && ady==0)))return 0;
break;
}
case 2:{
if(!(adx==1 && ady==1))return 0;
break;
}
case 3:{
if(adx!=2 || ady!=2 || mp[xs+dx/2][ys+dy/2].pos)return 0;
break;
}
case 4:{
if(adx==2 && ady==1){
if(mp[xs+dx/2][ys].pos)return 0;
}
else if(adx==1 && ady==2){
if(mp[xs][ys+dy/2].pos)return 0;
}
else{
//printf("hahaha\n");
return 0;
}
break;
}
case 5:{
if(adx && ady)return 0;
if(!adx){
for(int i=min(ys,yt)+1;i<max(ys,yt);++i){
if(mp[xs][i].pos)return 0;
}
}
else{
for(int i=min(xs,xt)+1;i<max(xs,xt);++i){
if(mp[i][ys].pos)return 0;
}
}
break;
}
case 6:{
if(adx==2 && ady==3){
if(mp[xs+dx/2][ys+dy/3*2].pos || mp[xs][ys+dy/3].pos)return 0;
}
else if(adx==3 && ady==2){
if(mp[xs+dx/3*2][ys+dy/2].pos || mp[xs+dx/3][ys].pos)return 0;
}
else return 0;
break;
}
case 7:{
if(!(adx<=1 && ady<=1))return 0;
break;
}
}
return 1;
}
inline bool jj(int cl){
xt=king[cl][0];yt=king[cl][1];
for(int i=9;i>=0;--i){
for(int j=0;j<=8;++j){
if(mp[i][j].pos && mp[i][j].clr!=cl){
xs=i;ys=j;
if(check(0))return 1;
}
}
}
return 0;
}
inline bool jiangjun()
{
if(flag)return 0;
return jj(0)||jj(1);
}
//void print()
//{
// for(int i=9;i>=0;--i){
// for(int j=0;j<=8;++j){
// cout<<mp[i][j].pos<<'('<<mp[i][j].clr<<')'<<' ';
// //if(mp[i][j].pos)
// }
// cout<<endl;
// }
//}
inline int read()
{
int x=0;char ch=getchar();
while(ch>'9' || ch<'0')ch=getchar();
while(ch<='9' && ch>='0'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x;
}
int main()
{
pre(0,0,5);pre(0,1,4);pre(0,2,3);pre(0,3,2);pre(0,4,1);
pre(2,0,6);
pre(3,0,7);pre(3,2,7);pre(3,4,7);
// print();
Q=read();
while(Q--){
xs=read();ys=read();xt=read();yt=read();
if(!check())
{
puts("Invalid command");
continue;
}
printf("%s%s;",col[opt].data(),name[mp[xs][ys].pos].data());
if(mp[xt][yt].pos==1){
flag=1;
}
if(mp[xt][yt].pos){
printf("%s%s;",col[!opt].data(),name[mp[xt][yt].pos].data());
}
else printf("NA;");
if(mp[xs][ys].pos==1){
king[opt][0]=xt;king[opt][1]=yt;
}
mp[xt][yt]=mp[xs][ys];
mp[xs][ys]=node{0,0};
printf("%s;%s",ok[jiangjun()].data(),ok[flag].data());puts("");
opt^=1;
// print();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3436kb
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: 2ms
memory: 3432kb
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: 3ms
memory: 3520kb
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: 2ms
memory: 3468kb
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