QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#400848 | #2821. 鸭棋 | vision | WA | 1ms | 3588kb | C++17 | 9.3kb | 2024-04-27 16:59:41 | 2024-04-27 16:59:41 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define lson k<<1
#define rson (k<<1)|1
#define debug cout<<666<<endl;
using namespace std;
const int N=1e6+5;
string qi[15];
int ne[5]={-1,1};
map<string,int>has;
int st[15][15];//-1 kong 0 lan 1 hong
int a[15][15];//qi zi
void inn(){
for(int i=0;i<=12;i++){
for(int j=0;j<=12;j++){
st[i][j]=-1;
}
}
qi[1]="captain"; qi[2]="guard"; qi[3]="elephant"; qi[4]="horse"; qi[5]="car"; qi[6]="duck"; qi[7]="soldier";
has["captain"]=1;has["guard"]=2;has["elephant"]=3;has["horse"]=4;has["car"]=5;has["duck"]=6;has["soldier"]=7;
for(int i=0;i<9;i++){
st[0][i]=1;st[9][i]=0;
}
st[3][0]=st[3][2]=a[3][4]=st[3][6]=st[3][8]=1;
st[6][0]=st[6][2]=st[6][4]=st[6][6]=st[6][8]=0;
st[2][0]=st[2][8]=1;st[7][0]=st[7][8]=0;
a[0][0]=a[9][0]=a[0][8]=a[9][8]=5;
a[0][1]=a[9][1]=a[0][7]=a[9][7]=4;
a[0][2]=a[9][2]=a[0][6]=a[9][6]=3;
a[0][3]=a[9][3]=a[0][5]=a[9][5]=2;
a[0][4]=a[9][4]=1;
a[2][0]=a[2][8]=a[7][0]=a[7][8]=6;
a[3][0]=a[3][2]=a[3][4]=a[3][6]=a[3][8]=7;
a[6][0]=a[6][2]=a[6][4]=a[6][6]=a[6][8]=7;
}
int move1(int sx,int sy,int tx,int ty){//0 buxing 1 keyi
if(abs(sx-tx)+abs(sy-ty)!=1)return 0;
if(st[sx][sy]==st[tx][ty])return 0;
return 1;
}
int move2(int sx,int sy,int tx,int ty){
if(abs(sx-tx)+abs(sy-ty)!=2)return 0;
if(st[sx][sy]==st[tx][ty])return 0;
return 1;
}
int move3(int sx,int sy,int tx,int ty){
if(st[sx][sy]==st[tx][ty])return 0;
if(abs(tx-sx)!=2||abs(ty-sy)!=2)return 0;
int tmp1=(sx+tx)/2,tmp2=(sy+ty)/2;
if(st[tmp1][tmp2]!=-1)return 0;
return 1;
}
int move4(int sx,int sy,int tx,int ty){
if(st[sx][sy]==st[tx][ty])return 0;
if(abs(tx-sx)==2){
if(abs(ty-sy)!=1)return 0;
int tmp=(tx+sx)/2;
if(st[tmp][sy]!=-1)return 0;
}
else if(abs(ty-sy)==2){
if(abs(tx-sx)!=1)return 0;
int tmp=(ty+sy)/2;
if(st[sx][tmp]!=-1)return 0;
}
else return 0;
return 1;
}
int move5(int sx,int sy,int tx,int ty){
if(st[sx][sy]==st[tx][ty])return 0;
if(tx!=sx&&sy!=sy)return 0;
if(tx==sx){
for(int i=min(ty,sy);i<=max(ty,sy);i++){
if(i==sy)continue;
if(st[sx][sy]==st[sx][i])return 0;
}
}
else {
for(int i=min(tx,sx);i<=max(sx,tx);i++){
if(i==sx)continue;
if(st[sx][sy]==st[i][sy])return 0;
}
}
return 1;
}
int move6(int sx,int sy,int tx,int ty){
// debug;
if(st[sx][sy]==st[tx][ty])return 0;
if(abs(tx-sx)==3){
if(abs(ty-sy)!=2)return 0;
int tmpy=(ty+sy)/2;
if(sx<tx){
if(st[sx+1][sy]!=-1||st[sx+2][tmpy]!=-1)return 0;
}
else {
// cout<<sx<<" "<<tmpy<<" ";
// cout<<st[6][0]<<" ";
if(st[sx-1][sy]!=-1||st[sx-2][tmpy]!=-1)return 0;
}
}
else if(abs(ty-sy)==3){
if(abs(tx-sx)!=2)return 0;
int tmpx=(tx+sx)/2;
if(sy<ty){
if(st[sx][sy+1]!=-1||st[tmpx][sy+2]!=-1)return 0;
}
else {
if(st[sx][sy-1]!=-1||st[tmpx][sy-2]!=-1)return 0;
}
}
else return 0;
return 1;
}
int move7(int sx,int sy,int tx,int ty){
if(abs(sx-tx)+abs(sy-ty)>2)return 0;
if(st[sx][sy]==st[tx][ty])return 0;
return 1;
}
int check(int x,int tx,int ty){//1 jiang jun
if(x==1){
for(int i=0;i<=1;i++){
if(a[tx+ne[i]][ty]==1&&st[tx+ne[i]][ty]!=st[tx][ty])return 1;
if(a[tx][ty+ne[i]]==1&&st[tx][ty+ne[i]]!=st[tx][ty])return 1;
}
}
else if(x==2){
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(a[tx+ne[i]][ty+ne[j]]==1&&st[tx+ne[i]][ty+ne[j]]!=st[tx][ty])return 1;
}
}
}
else if(x==3){
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(st[tx+ne[i]][ty+ne[j]]!=-1)continue;
if(a[tx+ne[i]*2][ty+ne[j]*2]==1&&st[tx+ne[i]*2][ty+ne[j]*2]!=st[tx][ty])return 1;
}
}
}
else if(x==4){
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(st[tx+ne[i]][ty]!=-1)continue;
if(a[tx+ne[i]*2][ty+ne[j]]==1&&st[tx+ne[i]*2][ty+ne[j]]!=st[tx][ty])return 1;
}
}
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(st[tx][ty+ne[i]]!=-1)continue;
if(a[tx+ne[i]][ty+ne[j]*2]==1&&st[tx+ne[i]][ty+ne[j]*2]!=st[tx][ty])return 1;
}
}
}
else if(x==5){
int tmp=1;
while(tx+tmp<=9){
if(st[tx+tmp][ty]!=-1){
if(a[tx+tmp][ty]==1&&st[tx+tmp][ty]!=st[tx][ty])return 1;
else break;
}
tmp++;
}
tmp=1;
while(ty+tmp<=8){
// cout<<tx<<":"<<ty<<" ";
if(st[tx][ty+tmp]!=-1){
if(a[tx][ty+tmp]==1&&st[tx][ty+tmp]!=st[tx][ty])return 1;
else break;
}
tmp++;
}
tmp=1;
while(ty-tmp>=0){
if(st[tx][ty-tmp]!=-1){
if(a[tx][ty-tmp]==1&&st[tx][ty-tmp]!=st[tx][ty])return 1;
else break;
}
tmp++;
}
tmp=1;
while(tx-tmp>=0){
if(st[tx-tmp][ty]!=-1){
if(a[tx-tmp][ty]==1&&st[tx-tmp][ty]!=st[tx][ty])return 1;
else break;
}
tmp++;
}
}
else if(x==6){
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(st[tx+ne[i]*2][ty+ne[j]]!=-1||st[tx+ne[i]][ty]!=-1)continue;
if(a[tx+ne[i]*3][ty+ne[j]*2]==1&&st[tx+ne[i]*3][ty+ne[j]*2]!=st[tx][ty])return 1;
}
}
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(st[tx+ne[i]][ty+ne[j]*2]!=-1||st[tx][ty+ne[i]]!=-1)continue;
if(a[tx+ne[i]*2][ty+ne[j]*3]==1&&st[tx+ne[i]*2][ty+ne[j]*3]!=st[tx][ty])return 1;
}
}
}
else if(x==7){
for(int i=0;i<=1;i++){
if(a[tx+ne[i]][ty]==1&&st[tx+ne[i]][ty]!=st[tx][ty])return 1;
if(a[tx][ty+ne[i]]==1&&st[tx][ty+ne[i]]!=st[tx][ty])return 1;
}
for(int i=0;i<=1;i++){
for(int j=0;j<=1;j++){
if(a[tx+ne[i]][ty+ne[j]]==1&&st[tx+ne[i]][ty+ne[j]]!=st[tx][ty])return 1;
}
}
}
return 0;
}
int ffff(){
for(int i=0;i<=9;i++){
for(int j=0;j<=8;j++){
if(st[i][j]!=-1){
if(check(a[i][j],i,j))return 1;
}
}
}
return 0;
}
void vision()
{
int Q;
cin>>Q;
int now=1;
int nmm=0;
while(Q--){
int tx,ty,sx,sy;
cin>>sx>>sy>>tx>>ty;
// cout<<a[sx][sy]<<" ";
if(nmm==1){
cout<<"Invalid command\n";
continue;
}
if(st[sx][sy]==-1||st[sx][sy]!=now){
// debug;
cout<<"Invalid command\n";
continue;
}
string ans;
if(now==1)ans=ans+"red ";
else if(now==0)ans=ans+"blue ";
ans=ans+qi[a[sx][sy]]+";";
if(a[sx][sy]==1){
if(move1(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
else if(a[sx][sy]==2){
if(move2(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
else if(a[sx][sy]==3){
if(move3(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
else if(a[sx][sy]==4){
if(move4(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
else if(a[sx][sy]==5){
if(move5(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
else if(a[sx][sy]==6){
if(move6(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
else if(a[sx][sy]==7){
if(move7(sx,sy,tx,ty)==0){
cout<<"Invalid command\n";
continue;
}
}
// cout<<tx<<" "<<ty<<" ";
int tmpst=st[tx][ty];
int tmpa=a[tx][ty];
a[tx][ty]=a[sx][sy];
a[sx][sy]=0;
st[tx][ty]=st[sx][sy];
st[sx][sy]=-1;
if(tmpst==0){
ans=ans+"blue ";
ans=ans+qi[tmpa]+";";
}
else if(tmpst==1){
ans=ans+"red ";
ans=ans+qi[tmpa]+";";
}
else {
ans=ans+"NA;";
}
if(ffff())ans=ans+"yes;";
else ans=ans+"no;";
if(tmpa==1)ans=ans+"yes",nmm=1;
else ans=ans+"no";
now=1-now;
cout<<ans<<"\n";
// cout<<a[9][3]<<" "<<a[9][4]<<"\n";
}
return ;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
inn();
vision();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
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: -100
Wrong Answer
time: 0ms
memory: 3588kb
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:
wrong answer 110th lines differ - expected: 'red soldier;NA;no;no', found: 'Invalid command'