QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420403 | #2821. 鸭棋 | 300_205_205# | AC ✓ | 1ms | 3876kb | C++14 | 5.8kb | 2024-05-24 17:27:04 | 2024-05-24 17:27:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long
#define ull unsigned ll
#define lowbit(x) (x&(-x))
#define djq 59393
const double eps=1e-10;
const short sint=0x3f3f;
const int inf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
const double alpha=0.73;
const double PI=acos(-1);
inline void file(){
freopen("entrench.in","r",stdin);
freopen("entrench.out","w",stdout);
}
inline ll read(){
rg ll ret=0,f=0;char ch=getchar();
while(!isdigit(ch)){if(ch==EOF)exit(0);if(ch=='-')f=1;ch=getchar();}
while(isdigit(ch)){ret=ret*10+ch-48;ch=getchar();}
return f?-ret:ret;
}
#define ep emplace
#define epb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define it iterator
#define mkp make_pair
#define naive return 0*puts("Yes")
#define angry return 0*puts("No")
#define fls fflush(stdout)
#define rep(i,x,y) for(rg int i=(x);i<=(y);++i)
#define per(i,x,y) for(rg int i=(x);i>=(y);--i)
#define rep0(i,a) for(rg int i=0;i<=a;++i)
#define per0(i,a) for(rg int i=a;~i;--i)
#define szf sizeof
typedef vector<int> vec;
typedef pair<int,int> pii;
struct point{ int x,y; point(int x=0,int y=0):x(x),y(y) {} inline bool operator<(const point& T)const{ return x^T.x?x<T.x:y<T.y; }; };
inline int ksm(int base,int p){int ret=1;while(p){if(p&1)ret=1ll*ret*base%djq;base=1ll*base*base%djq,p>>=1;}return ret;}
inline void pls(int& x,const int k){ x=(x+k>=djq?x+k-djq:x+k); }
inline int add(const int a,const int b){ return a+b>=djq?a+b-djq:a+b; }
inline void sub(int& x,const int k){ x=(x-k<0?x-k+djq:x-k); }
inline int inc(const int a,const int b){ return a<b?a-b+djq:a-b; }
inline void ckmn(int& x,const int k){ x=(k<x?k:x); }
inline void ckmx(int& x,const int k){ x=(k>x?k:x); }
inline void ckmn(ll& x,const ll k){ x=(k<x?k:x); }
inline void ckmx(ll& x,const ll k){ x=(k>x?k:x); }
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int dx1[]={0,0,1,-1};
const int dy1[]={1,-1,0,0};
const int dx2[]={1,1,-1,-1};
const int dy2[]={1,-1,1,-1};
int mp[10][9],col[10][9],is_end,op;
inline int ps(int x,int y){ return x>=0&&x<10&&y>=0&&y<9; }
string name(int x,int y){
assert(ps(x,y)&&col[x][y]>=0&&col[x][y]<=1&&mp[x][y]>=1&&mp[x][y]<=7);
string res="";
if(col[x][y]==0) res=res+"red ";
else res=res+"blue ";
if(mp[x][y]==1) res=res+"captain";
if(mp[x][y]==2) res=res+"guard";
if(mp[x][y]==3) res=res+"elephant";
if(mp[x][y]==4) res=res+"horse";
if(mp[x][y]==5) res=res+"car";
if(mp[x][y]==6) res=res+"duck";
if(mp[x][y]==7) res=res+"soldier";
return res;
}
int chk_move(int sx,int sy,int tx,int ty){
if(mp[sx][sy]==1){
rep(i,0,3) if(sx+dx1[i]==tx&&sy+dy1[i]==ty) return 1;
return 0;
}else if(mp[sx][sy]==2){
rep(i,0,3) if(sx+dx2[i]==tx&&sy+dy2[i]==ty) return 1;
return 0;
}else if(mp[sx][sy]==3){
rep(i,0,3) if(sx+dx2[i]*2==tx&&sy+dy2[i]*2==ty&&mp[sx+dx2[i]][sy+dy2[i]]==0) return 1;
return 0;
}else if(mp[sx][sy]==4){
rep(i,0,3){
if(sx+dx2[i]*2==tx&&sy+dy2[i]==ty&&mp[sx+dx2[i]][sy]==0) return 1;
if(sx+dx2[i]==tx&&sy+dy2[i]*2==ty&&mp[sx][sy+dy2[i]]==0) return 1;
}
return 0;
}else if(mp[sx][sy]==5){
if(sx==tx){
rep(i,min(sy,ty)+1,max(sy,ty)-1) if(mp[sx][i]) return 0;
return 1;
}else if(sy==ty){
rep(i,min(sx,tx)+1,max(sx,tx)-1) if(mp[i][sy]) return 0;
return 1;
}
return 0;
}else if(mp[sx][sy]==6){
rep(i,0,3){
if(sx+dx2[i]*3==tx&&sy+dy2[i]*2==ty&&mp[sx+dx2[i]][sy]==0&&mp[sx+dx2[i]*2][sy+dy2[i]]==0) return 1;
if(sx+dx2[i]*2==tx&&sy+dy2[i]*3==ty&&mp[sx][sy+dy2[i]]==0&&mp[sx+dx2[i]][sy+dy2[i]*2]==0) return 1;
}
return 0;
}else if(mp[sx][sy]==7){
rep(i,0,3) if(sx+dx1[i]==tx&&sy+dy1[i]==ty) return 1;
rep(i,0,3) if(sx+dx2[i]==tx&&sy+dy2[i]==ty) return 1;
return 0;
}else assert(0);
return 0;
}
int chk_legal(int sx,int sy,int tx,int ty){
if(is_end) return 0;
if(col[sx][sy]!=op||col[tx][ty]==op) return 0;
return chk_move(sx,sy,tx,ty);
}
pii chk_mate(){
int cnt[2]={0,0};
pii pt[2];
rep(x,0,9)
rep(y,0,8)
if(mp[x][y]==1) assert(col[x][y]==0||col[x][y]==1),++cnt[col[x][y]],pt[col[x][y]]=mkp(x,y);
assert(cnt[0]<=1&&cnt[1]<=1);
int res0=0,res1=0;
res0=(cnt[0]<1||cnt[1]<1);
if(!res0){
rep(x,0,9){
rep(y,0,8){
if(mp[x][y]==0) continue;
assert(col[x][y]==0||col[x][y]==1);
if(chk_move(x,y,pt[col[x][y]^1].fi,pt[col[x][y]^1].se)){ res1=1; break; }
}
if(res1) break;
}
}
return mkp(res0,res1);
}
signed main(){
// file();
int _=read();
is_end=0; op=0;
memset(col,-1,sizeof(col));
memset(mp,0,sizeof(mp));
mp[0][4]=mp[9][4]=1,col[0][4]=0,col[9][4]=1;
mp[0][3]=mp[0][5]=mp[9][3]=mp[9][5]=2,col[0][3]=col[0][5]=0,col[9][3]=col[9][5]=1;
mp[0][2]=mp[0][6]=mp[9][2]=mp[9][6]=3,col[0][2]=col[0][6]=0,col[9][2]=col[9][6]=1;
mp[0][1]=mp[0][7]=mp[9][1]=mp[9][7]=4,col[0][1]=col[0][7]=0,col[9][1]=col[9][7]=1;
mp[0][0]=mp[0][8]=mp[9][0]=mp[9][8]=5,col[0][0]=col[0][8]=0,col[9][0]=col[9][8]=1;
mp[2][0]=mp[2][8]=mp[7][0]=mp[7][8]=6,col[2][0]=col[2][8]=0,col[7][0]=col[7][8]=1;
mp[3][0]=mp[3][2]=mp[3][4]=mp[3][6]=mp[3][8]=7,col[3][0]=col[3][2]=col[3][4]=col[3][6]=col[3][8]=0;
mp[6][0]=mp[6][2]=mp[6][4]=mp[6][6]=mp[6][8]=7,col[6][0]=col[6][2]=col[6][4]=col[6][6]=col[6][8]=1;
while(_--){
int sx=read(),sy=read(),tx=read(),ty=read();
if(!chk_legal(sx,sy,tx,ty)){ puts("Invalid command"); continue; }
string oput="";
oput=oput+name(sx,sy);
oput=oput+";";
if(mp[tx][ty]) oput=oput+name(tx,ty);
else oput=oput+"NA";
oput=oput+";";
col[tx][ty]=col[sx][sy],mp[tx][ty]=mp[sx][sy];
col[sx][sy]=-1,mp[sx][sy]=0;
pii chk_result=chk_mate();
if(chk_result.se) oput=oput+"yes";
else oput=oput+"no";
oput=oput+";";
is_end=chk_result.fi;
if(is_end) oput=oput+"yes";
else oput=oput+"no";
cout<<oput<<"\n";
op^=1;
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3876kb
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: 3572kb
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: 0ms
memory: 3704kb
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: 3864kb
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