QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106688 | #6314. 过河卒 | sichengzhou | 100 ✓ | 632ms | 19400kb | C++14 | 4.7kb | 2023-05-18 20:26:14 | 2023-05-18 20:26:17 |
Judging History
answer
#include<bits/stdc++.h>
#define pdx pd[x1][Y1][x2][y2][x3][y3]
#define dpx dp[x1][Y1][x2][y2][x3][y3]
#define dx d[x1][Y1][x2][y2][x3][y3]
#define idx (int)(1e6*x1+1e5*Y1+1e4*x2+1e3*y2+1e2*x3+1e1*y3+i)
using namespace std;
const int N=10,M=4e6+10;
int n,m,pd1,f1,id1;
char ch[N][N];
int dp[N][N][N][N][N][N],pd[N][N][N][N][N][N],d[N][N][N][N][N][N];
int q[M],hh,tt;
int i,x1,Y1,x2,y2,x3,y3;
void work()
{
if(pdx)
{
return ;
}
if(id1==0121020)
{
cout<<id1<<endl;
}
if(pd1==1)
{
pdx=2;
dpx=f1+1;
dx=0;
q[++tt]=idx;
}else{
dpx=f1+1;
dx--;
if(dx==0)
{
q[++tt]=idx;
pdx=1;
}
}
}
int a1,b1,a2,b2,a3,b3;
void work1()
{
memset(pd,0,sizeof(pd));
memset(dp,0,sizeof(dp));
memset(d,0,sizeof(d));
hh=1,tt=0;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%s",ch[i]);
}
a1=-1;b1=-1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(ch[i][j]=='O')
{
if(a1==-1)
{
a1=i,b1=j;
}else{
a2=i,b2=j;
}
}else if(ch[i][j]=='X')
{
a3=i,b3=j;
}
}
}
// cout<<"**\n";
for(int x1=0;x1<n;x1++)
{
for(int Y1=0;Y1<m;Y1++)
{
for(int x2=0;x2<n;x2++)
{
for(int y2=0;y2<m;y2++)
{
for(int x3=0;x3<n;x3++)
{
for(int y3=0;y3<m;y3++)
{
int i=(abs(x1-a1)+abs(Y1-b1)
+abs(x2-a2)+abs(y2-b2)
+abs(x3-a3)+abs(y3-b3))&1;
{
if((ch[x1][Y1]=='#'||ch[x2][y2]=='#')&&i==1||
ch[x3][y3]=='#'&&i==0
||x1==x2&&Y1==y2&&i==1)
{
dp[x1][Y1][x2][y2][x3][y3]=-1;
pd[x1][Y1][x2][y2][x3][y3]=2;
continue;
}
if(x3==0&&i==0)
{
dp[x1][Y1][x2][y2][x3][y3]=0;
pd[x1][Y1][x2][y2][x3][y3]=1;
continue;
}
if(x1==x3&&Y1==y3||x2==x3&&y2==y3)
{
dp[x1][Y1][x2][y2][x3][y3]=0;
// if(x2*y2*x3*y3==1)cout<<x1<<' '<<Y1<<' '<<i<<endl;
pd[x1][Y1][x2][y2][x3][y3]=1;
continue;
}
}
}
}
}
}
}
}
// cout<<dp[0][1][2][1][0][2]<<' '<<pd[0][1][2][1][0][2]<<endl;
// cout<<"**\n";
for(int x1=0;x1<n;x1++)
{
for(int Y1=0;Y1<m;Y1++)
{
for(int x2=0;x2<n;x2++)
{
for(int y2=0;y2<m;y2++)
{
for(int x3=0;x3<n;x3++)
{
for(int y3=0;y3<m;y3++)
{
int i=(abs(x1-a1)+abs(Y1-b1)
+abs(x2-a2)+abs(y2-b2)
+abs(x3-a3)+abs(y3-b3))&1;
{
if(pd[x1][Y1][x2][y2][x3][y3])
{
q[++tt]=x1*1e6+Y1*1e5+x2*1e4+y2*1e3+x3*1e2+y3*1e1+i;
continue;
}
// cout<<tt<<endl;
if(i==0)
{
d[x1][Y1][x2][y2][x3][y3]=(x1>0)+(x1<n-1)
+(Y1>0)+(Y1<m-1)+(x2>0)+(x2<n-1)+(y2>0)+(y2<m-1);
}else{
d[x1][Y1][x2][y2][x3][y3]=(x3>0)+(y3>0)+(y3<m-1);
}
}
}
}
}
}
}
}
// cout<<tt<<endl;
// cout<<"**\n";
while(hh<=tt)
{
// cout<<q[hh]<<endl;getchar();
i=q[hh]%10,y3=q[hh]/10%10,x3=q[hh]/100%10,y2=q[hh]/1000%10,
x2=q[hh]/10000%10,Y1=q[hh]/100000%10,x1=q[hh]/1000000%10;hh++;
pd1=pd[x1][Y1][x2][y2][x3][y3];
f1=dp[x1][Y1][x2][y2][x3][y3];
id1=idx;
if(i==0)
{
i^=1;
if(x3<n-1)
{
x3++;work();x3--;
}
if(y3>0)
{
y3--;work();y3++;
}
if(y3<m-1)
{
y3++;work();y3--;
}
i^=1;
}else{
i^=1;
if(x2>0)
{
x2--;work();x2++;
}
if(x2<n-1)
{
x2++;work();x2--;
}
if(y2>0)
{
y2--;work();y2++;
}
if(y2<m-1)
{
y2++;work();y2--;
}
if(x1>0)
{
x1--;work();x1++;
}
if(x1<n-1)
{
x1++;work();x1--;
}
if(Y1>0)
{
Y1--;work();Y1++;
}
if(Y1<m-1)
{
Y1++;work();Y1--;
}
i^=1;
}
}
// cout<<tt<<endl;
i=0;x1=a1,Y1=b1,x2=a2,y2=b2,x3=a3,y3=b3;
if(pdx==0)
{
printf("Tie\n");
}else if(pdx==1)
{
printf("Black %d\n",dpx);
}else{
printf("Red %d\n",dpx);
}
// cout<<a1<<' '<<b1<<' '<<a2<<' '<<b2<<' '<<a3<<' '<<b3<<endl;
// cout<<dx<<endl;
// cout<<dp[0][1][2][1][0][2]<<' '<<pd[0][1][2][1][0][2]<<endl;
/* cout<<d[1][1][1][2][2][1][1]<<' '<<pd[1][1][1][2][2][1][1]<<endl;
cout<<d[1][0][1][1][2][1][1]<<' '<<pd[1][0][1][1][2][1][1]<<endl;
cout<<dp[1][1][1][2][1][1][0]<<' '<<pd[1][1][1][2][1][1][0]<<endl;
cout<<dp[1][0][1][1][1][1][0]<<' '<<pd[1][0][1][1][1][1][0]<<endl;*/
}
/*
9 9
...######
.#.......
.#######.
.#.#.....
.#O#.####
.#.#.....
.#######.
.#X......
.O.......
*/
int main()
{
int T;
scanf("%d",&T);
scanf("%d",&T);
while(T--)
{
work1();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 544ms
memory: 19212kb
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: 486ms
memory: 19172kb
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: 549ms
memory: 19116kb
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: 476ms
memory: 19184kb
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: 472ms
memory: 19136kb
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: 403ms
memory: 19152kb
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: 9ms
memory: 15248kb
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: 9ms
memory: 15228kb
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: 10ms
memory: 15316kb
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: 583ms
memory: 19208kb
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: 599ms
memory: 19148kb
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: 476ms
memory: 19212kb
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: 553ms
memory: 19172kb
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: 626ms
memory: 19216kb
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: 545ms
memory: 19168kb
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: 560ms
memory: 19176kb
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: 632ms
memory: 19172kb
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: 548ms
memory: 19400kb
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: 606ms
memory: 19156kb
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: 593ms
memory: 19344kb
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