QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#96629 | #6314. 过河卒 | SoyTony | 100 ✓ | 506ms | 86756kb | C++14 | 7.2kb | 2023-04-14 21:54:21 | 2023-04-14 21:54:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef pair<int,int> pii;
#define x first
#define y second
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int t,n,m;
char s[15][15];
pii B,R1,R2;
struct state{
pii bp,rp1,rp2;
//0->B 1->R
state()=default;
state(pii bp_,pii rp1_,pii rp2_):bp(bp_),rp1(rp1_),rp2(rp2_){}
}S[maxn];
bool opt[maxn];
int winchk[maxn];
int mp[11][11][11][11][11][11];
int tot,mark;
int dx[4]={-1,0,0,1},dy[4]={0,-1,1,0};
struct edge{
int to,nxt;
}e[maxn<<3];
int head[maxn],cnt;
int deg[maxn];
inline void add_edge(int u,int v){
e[++cnt].to=v,e[cnt].nxt=head[u],head[u]=cnt;
++deg[v];
}
queue<int> q;
int dp[maxn];
int main(){
// freopen("zu2.in","r",stdin);
// freopen("zu.out","w",stdout);
read(),t=read();
while(t--){
n=read(),m=read();
for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
B=R1=R2=make_pair(0,0);
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(s[i][j]=='X') B=make_pair(i,j);
if(s[i][j]=='O'){
if(!R1.x) R1=make_pair(i,j);
else R2=make_pair(i,j);
}
}
}
tot=0;
memset(mp,0,sizeof(mp));
for(int bx=1;bx<=n;++bx){
for(int by=1;by<=m;++by){
for(int rx1=1;rx1<=n;++rx1){
for(int ry1=1;ry1<=m;++ry1){
for(int rx2=1;rx2<=n;++rx2){
for(int ry2=1;ry2<=m;++ry2){
pii bnow=make_pair(bx,by),rnow1=make_pair(rx1,ry1),rnow2=make_pair(rx2,ry2);
if(bx>B.x) continue;
if(s[bnow.x][bnow.y]=='#'||s[rnow1.x][rnow1.y]=='#'||s[rnow2.x][rnow2.y]=='#') continue;
if(rnow1==rnow2) continue;
int sumstep=abs(B.x-bx)+abs(B.y-by)+abs(R1.x-rx1)+abs(R1.y-ry1)+abs(R2.x-rx2)+abs(R2.y-ry2);
S[++tot]=state(bnow,rnow1,rnow2),opt[tot]=sumstep&1^1,winchk[tot]=-1;
if(bnow.x==1) winchk[tot]=0;
else if(bnow==rnow1||bnow==rnow2) winchk[tot]=opt[tot]^1;
else{
if(!opt[tot]){
bool chk=1;
for(int i=0;i<3;++i){
int xx=bnow.x+dx[i],yy=bnow.y+dy[i];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(s[xx][yy]!='#') chk=0;
}
if(chk) winchk[tot]=1;
}
else{
bool chk=1;
for(int i=0;i<4;++i){
int xx=rnow1.x+dx[i],yy=rnow1.y+dy[i];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(s[xx][yy]!='#'&&make_pair(xx,yy)!=rnow2) chk=0;
}
for(int i=0;i<4;++i){
int xx=rnow2.x+dx[i],yy=rnow2.y+dy[i];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(s[xx][yy]!='#'&&make_pair(xx,yy)!=rnow1) chk=0;
}
if(chk) winchk[tot]=0;
}
}
mp[bx][by][rx1][ry1][rx2][ry2]=tot;
// printf("%d (%d %d) (%d %d) (%d %d)\n",tot,S[tot].bp.x,S[tot].bp.y,S[tot].rp1.x,S[tot].rp1.y,S[tot].rp2.x,S[tot].rp2.y);
if(bnow==B&&rnow1==R1&&rnow2==R2) mark=tot;
}
}
}
}
}
}
// printf("%d\n",mark);
for(int i=1;i<=tot;++i) head[i]=0,deg[i]=0;
cnt=0;
for(int i=1;i<=tot;++i){
if(winchk[i]!=-1) q.push(i);
pii bnow=S[i].bp,rnow1=S[i].rp1,rnow2=S[i].rp2;
if(!opt[i]){
//move R
for(int j=0;j<4;++j){
int xx=rnow1.x+dx[j],yy=rnow1.y+dy[j];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(mp[bnow.x][bnow.y][xx][yy][rnow2.x][rnow2.y]){
int nxt=mp[bnow.x][bnow.y][xx][yy][rnow2.x][rnow2.y];
if(winchk[nxt]!=-1) continue;
add_edge(i,nxt);
}
}
for(int j=0;j<4;++j){
int xx=rnow2.x+dx[j],yy=rnow2.y+dy[j];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(mp[bnow.x][bnow.y][rnow1.x][rnow1.y][xx][yy]){
int nxt=mp[bnow.x][bnow.y][rnow1.x][rnow1.y][xx][yy];
if(winchk[nxt]!=-1) continue;
add_edge(i,nxt);
}
}
}
else{
//move B
for(int j=1;j<4;++j){
int xx=bnow.x+dx[j],yy=bnow.y+dy[j];
if(xx<1||xx>n||yy<1||yy>m) continue;
if(mp[xx][yy][rnow1.x][rnow1.y][rnow2.x][rnow2.y]){
int nxt=mp[xx][yy][rnow1.x][rnow1.y][rnow2.x][rnow2.y];
if(winchk[nxt]!=-1) continue;
add_edge(i,nxt);
}
}
}
}
for(int i=1;i<=tot;++i) dp[i]=0;
int qcnt=0;
while(!q.empty()){
++qcnt;
int u=q.front();
q.pop();
// printf("%d (%d %d) (%d %d) (%d %d) opt:%d winchk:%d dp:%d\n",u,S[u].bp.x,S[u].bp.y,S[u].rp1.x,S[u].rp1.y,S[u].rp2.x,S[u].rp2.y,opt[u],winchk[u],dp[u]);
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(winchk[u]==opt[u]){
//必败策略
if(winchk[v]==opt[v]) continue;
winchk[v]=opt[v]^1,dp[v]=max(dp[v],dp[u]+1);
--deg[v];
if(!deg[v]) q.push(v);
}
else{
//必胜策略
if(winchk[v]==opt[v]) continue;
winchk[v]=opt[v],dp[v]=dp[u]+1;
deg[v]=0;
q.push(v);
}
}
}
// cerr<<qcnt<<endl;
if(winchk[mark]==-1) printf("Tie\n");
else if(winchk[mark]==opt[mark]) printf("Red %d\n",dp[mark]);
else if(!deg[mark]) printf("Black %d\n",dp[mark]);
else printf("Tie\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 171ms
memory: 47816kb
input:
1 10 10 10 .#......#. ..#....#.. #..#..#..# ..#.O..#.. .#......#. ...####... ##..X...## .......... .##.O####. .......... 10 10 .##..##... .....##... ..X#.#.... #........# ..#.#.#... .#...#.#.. #..#.#.#.. ..#..#.#.# ...##O#... ..##O#.#.. 4 1 O O # X 10 10 .##.....## ...#....## .#.#...#.. .O###..... #...
output:
Tie Black 0 Black 0 Tie Black 0 Tie Black 0 Black 0 Tie Tie
result:
ok 10 lines
Test #2:
score: 5
Accepted
time: 185ms
memory: 64688kb
input:
2 10 10 10 .#.####..# .##..##### ##.###X### #....####. .#.####### #.#O###.## ..##.####. ..######## ########## ##O#.#.### 10 10 ..#.###.## ......#..# ....#O.... #..#.....# ...#.##### .....#..#. ..#.....#O X#....###. #.....##.. .#..##.... 10 10 .......##. .O##...##. ..#....... ####..O... ....#...## .....
output:
Black 0 Tie Tie Black 0 Black 0 Tie Black 0 Tie Tie Black 0
result:
ok 10 lines
Test #3:
score: 5
Accepted
time: 143ms
memory: 49940kb
input:
3 10 10 10 ##.####### ###..###OO ##X####.## ...####### #..###...# ##...##### ##..#.#### ..##..##.# ###..#.#.# #.###..##. 10 10 .##..##... .....##... ..X#.#.... #........# ..#.#.#... .#...#.#.. #..#.#.#.. ..#..#.#.# ...##O#... ..##O#.#.. 10 10 .......... .X........ .......... .......... ..#....... .....
output:
Black 0 Black 0 Black 0 Black 0 Black 0 Tie Tie Tie Tie Tie
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 177ms
memory: 39448kb
input:
4 10 10 10 .#......#. ..#....#.. #..#..#..# ..#.O..#.. .#......#. ...####... ##..X...## .......... .##.O####. .......... 10 10 ...#.##... ..####.##. ###.###### .####O#.X# ...####..# .##O#..#.# ##.#..###. #.#.#....# .#.#####.# .##.#.#.## 3 2 OO ## #X 10 10 .##.##...# ..##..#.#O .#O#.#...# #.#.#..##. ...
output:
Tie Black 0 Black 0 Black 0 Black 0 Black 0 Tie Tie Tie Tie
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 385ms
memory: 65740kb
input:
5 10 10 10 .......... ....O..... .......... ...X...... .......... .......... .......... .......... ########## .......O.. 10 10 .......... ..O....... .......... .......... .......... X......... .......... .......... ########## .......O.. 10 1 . . . O . . . X # O 10 1 O . . . . . . X # O 10 10 ..........
output:
Red 9 Red 21 Black 12 Red 7 Black 8 Red 23 Black 14 Red 25 Red 23 Red 1
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 332ms
memory: 64964kb
input:
6 10 10 10 .....O.... .......... .......... .......... .......... .X........ .......... .......... ########## ...O...... 10 1 O . . . . . . X # O 10 10 .......... ..O....... .......... .......... .......... X......... .......... .......... ########## .......O.. 10 10 .......... .....O.... .............
output:
Red 17 Red 7 Red 21 Red 17 Black 2 Black 12 Black 6 Red 25 Red 23 Black 10
result:
ok 10 lines
Test #7:
score: 5
Accepted
time: 2ms
memory: 21960kb
input:
7 10 10 1 . O # . . X . # . O 10 1 O . . . . . . X . O 10 1 . . # O O # # . . X 5 1 O O . X . 10 1 O # . . . . . X . O 9 1 O # O . . . . . X 10 1 . . . . X O . # . O 10 1 O O . # . . . . . X 10 1 . . . . . . X . O O 10 1 O . . . # X # O . .
output:
Red 5 Red 7 Black 0 Black 2 Red 11 Black 10 Red 1 Red 11 Black 12 Red 1
result:
ok 10 lines
Test #8:
score: 5
Accepted
time: 5ms
memory: 24036kb
input:
8 10 10 1 . . # . X # . O # O 10 1 . O O . X . . . . . 10 1 O O . . . . . . . X 5 1 . # O X O 10 1 O # . . . . X . . O 9 1 O # O . . . . X . 10 1 # . . . X O . # . O 10 1 O O # # . . . . . X 10 1 # . . . . . X . O O 10 1 . # O . # O . X # .
output:
Red 3 Red 3 Red 9 Red 1 Red 9 Red 5 Red 1 Black 0 Red 11 Red 3
result:
ok 10 lines
Test #9:
score: 5
Accepted
time: 6ms
memory: 22072kb
input:
9 10 10 1 # O # . . X . # . O 10 1 O . . . X . . . . O 10 1 . . # O O . # . . X 5 1 O O . X . 10 1 O # . # . . . X . O 9 1 O . # O . . . X . 10 1 . . . . X O . . . O 10 1 O O . # # . . . . X 10 1 . . . . X . # . O O 10 1 . # O # O . . X # .
output:
Red 5 Red 5 Red 5 Black 2 Red 7 Red 5 Red 1 Red 9 Black 8 Red 3
result:
ok 10 lines
Test #10:
score: 5
Accepted
time: 244ms
memory: 71016kb
input:
10 10 10 10 .###..###. .....O...# .##.#..... ..##.##.X# ##......#. #...#..... ....##...# ..#..O##.# #..#.##... .....##.#. 10 10 #...##..#. #......##. ..##....#. #.#.##..#O .O...#.##. .....##.X. .###...... ....#.#.#. .......##. ###...##.# 10 10 #.#....... ..##..##.. ..##.#X..O ....#..... #..#....#. #...
output:
Red 7 Red 5 Red 3 Black 2 Red 9 Tie Tie Red 9 Red 9 Red 7
result:
ok 10 lines
Test #11:
score: 5
Accepted
time: 331ms
memory: 86756kb
input:
11 10 10 10 ...#.....# ..#....... ##.##.###. ##...#.##X .....#...# ...#.#.O.# ..#...#... .....#.... ......#..# #...#...O# 10 10 ..###O#O#. .#.###.##. ##..#..#.. ....#X.... ........## ........## #...##.... ...#..###. ........#. ..#...#.#. 10 10 ######...# O.X.O####. #.#.#.#... #.......#. ...##...#. ....
output:
Black 8 Black 0 Black 2 Tie Tie Red 9 Tie Red 9 Red 9 Red 1
result:
ok 10 lines
Test #12:
score: 5
Accepted
time: 339ms
memory: 83236kb
input:
12 10 10 10 ##..##..O. .#........ .#.......# .......... #......... .XO##..... #......... .......... .......... .......... 5 6 #.#### #.#### #.OO## #X#### ###### 10 10 ....###### .######### O...##.### .######### ....###### ####....#. ####.####. ####.O..#. #######.#. ####....#X 10 10 .......... .........
output:
Red 1 Black 2 Red 9 Tie Red 9 Black 6 Tie Tie Red 3 Tie
result:
ok 10 lines
Test #13:
score: 5
Accepted
time: 228ms
memory: 60216kb
input:
13 10 10 10 .##...#... .#####..## #..#..#..# #........# #...#.#.#. ....#..... ..#####... ....#..#.. ..##O#.... .X...O##.# 10 10 .##......# ..#..##..O ...#.##... ##..#O..## ..#...#... ###.....#X ..#....... .##.#.#... .#.#.#..#. #......#.# 10 10 .........# .......... O......... .......... ....O..... ....
output:
Black 6 Red 9 Red 9 Red 9 Black 8 Tie Red 7 Red 7 Tie Tie
result:
ok 10 lines
Test #14:
score: 5
Accepted
time: 506ms
memory: 86648kb
input:
14 10 10 10 .......O.. .......... .......... O......... .......... .......... .......... .......... .......X.. .......... 10 10 .##...#... .#####..## ...#..##.# #........# #...#.#.#. ....#..... ..#####... ....#..#.. ..##O#.... .X...O##.# 10 10 .#..O...#. ...####... ##.X....## .......... .#.O..#... ....
output:
Red 27 Black 6 Tie Black 8 Red 17 Red 63 Black 12 Red 17 Black 16 Red 5
result:
ok 10 lines
Test #15:
score: 5
Accepted
time: 227ms
memory: 48312kb
input:
15 10 10 10 .########O .........# ########.# .........# .######### .......... #########. .......... .######### .......O.X 10 10 .##...#... .#####..## ...#..##.# #........# #...#.#.#. ....#..... ..#####... ....#..#.. ..##O#.... .X...O##.# 10 8 ####.... ...#..#. .###..#. ...#.O#. ##.#..#. ...####. .##...
output:
Black 102 Black 6 Red 13 Red 9 Tie Red 63 Red 93 Red 139 Red 45 Black 44
result:
ok 10 lines
Test #16:
score: 5
Accepted
time: 220ms
memory: 49864kb
input:
16 10 10 10 ....###### .######### O...##.### .######### ....###### ####....#. ####.####. ####.O..#. #######.#. ####....#X 10 10 .#..O...#. ...####... ##.X....## .......... .#.O..#... .#....#... .#....#... ..####.... .......... .......... 10 10 O######### #..#..#... ..#..#..## .#..#..#.. ...#..#..# ....
output:
Red 9 Tie Black 50 Red 333 Red 41 Black 6 Red 133 Black 24 Red 111 Red 101
result:
ok 10 lines
Test #17:
score: 5
Accepted
time: 391ms
memory: 60544kb
input:
17 10 10 10 ########## .......... .......... ..######## .......... #########. .O........ .......... #......... O#X....... 10 10 .##...#... .#####..## ...#..##.# #........# #...#.#.#. ....#..... ..#####... ....#..#.. ..##O#.... .X...O##.# 10 10 #.......O. ..#....... ...##.##.. .......... .......... ....
output:
Black 60 Black 6 Red 53 Red 35 Tie Tie Red 9 Red 65 Tie Red 63
result:
ok 10 lines
Test #18:
score: 5
Accepted
time: 296ms
memory: 56320kb
input:
18 10 10 10 O......... #..#..###. .#.##...#. ..X....... .####..... .##...##.# ...#..###. ...###..O# ..#..#.... .......### 10 10 ...#.....O ........#. ........X. .......... ...#...... .......... .........# .....O.... ..#....... .......... 10 10 ..O.#..... #.#...#... ...#..###. ....#..... ..#..#..#. #...
output:
Red 159 Tie Red 73 Black 36 Black 56 Black 6 Red 15 Black 0 Red 63 Black 2
result:
ok 10 lines
Test #19:
score: 5
Accepted
time: 275ms
memory: 63812kb
input:
19 10 10 10 .....#.... ...#.#.#.# #..#.##.#. .##.....#. .#..##.#.# ...#...... #.#.#.##.. ##...#O##. ..#.#O.... .#...#..X. 10 10 .O....#... .####....# .###...#.. .......... ###....##. ....#..##. .#.#.#.... .##.O#..#. #..#...#.. ...#....X# 10 10 O######### #..#..#... ..#..#..## .#..#..#.. ...#..#..# ....
output:
Black 6 Red 57 Black 50 Red 11 Tie Red 129 Red 99 Black 0 Red 111 Red 27
result:
ok 10 lines
Test #20:
score: 5
Accepted
time: 276ms
memory: 49864kb
input:
20 10 10 10 .##.....## ...#....## .#.#...#.. .O###..... ###....... ......###. .....#..O. ##........ ..#...X... .##....... 10 10 #...#.##.. .O##.....# #.#.....#. .#...#.... ....#..#.. .###...... ....O##.#. .#.#.....# .......... .#.#...X#. 10 10 ......###. ..#.#..##. .#.......# .#.#..###. ..#.#..#.. #...
output:
Tie Red 63 Red 61 Red 9 Black 6 Black 0 Tie Red 333 Red 57 Tie
result:
ok 10 lines
Extra Test:
score: 0
Extra Test Passed