QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#509104 | #6314. 过河卒 | TheRaptor# | 30 | 830ms | 55136kb | C++14 | 6.3kb | 2024-08-08 10:15:48 | 2024-08-08 10:15:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int pot[2][11][11][11][11][11][11];
pair<int,int> ans[2][11][11][11][11][11][11];
pair<int,int> db[]={{-1,0},{0,1},{0,-1}},dr[]={{-1,0},{1,0},{0,1},{0,-1}};
queue<tuple<pair<int,int>,int,pair<int,int>,pair<int,int>,pair<int,int> > > q;
//0 is red, 1 is black
// win, num turn, who turn, 2x red pos, black pos
int n,m;
int arr[11][11];
bool valid(int x, int y){
if(x<0||x>=n||y<0||y>=m) return false;
if(arr[x][y]==1) return false;
return true;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int st,t;
cin >> st >> t;
while(t--){
cin >> n >> m;
pair<int,int> str[3];
bool got=false;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
char c;
cin >> c;
arr[i][j]=0;
if(c=='.') continue;
if(c=='#') arr[i][j]=1;
else if(c=='X') str[2]={i,j};
else if(!got) str[0]={i,j},got=true;
else str[1]={i,j};
}
}
for(int a1=0; a1<n; a1++) for(int a2=0; a2<m; a2++) for(int a3=0; a3<n; a3++){
for(int a4=0; a4<m; a4++) for(int a5=0; a5<n; a5++) for(int a6=0; a6<m; a6++){
pot[0][a1][a2][a3][a4][a5][a6]=0;
if(!(valid(a1,a2)&&valid(a3,a4)&&valid(a5,a6))) continue;
for(auto [i,j]:dr){
int nx=a1+i,ny=a2+j;
if(!valid(nx,ny)) continue;
if(nx==a3&&ny==a4) continue;
pot[0][a1][a2][a3][a4][a5][a6]++;
}
for(auto [i,j]:dr){
int nx=a3+i,ny=a4+j;
if(!valid(nx,ny)) continue;
if(nx==a1&&ny==a2) continue;
pot[0][a1][a2][a3][a4][a5][a6]++;
}
pot[1][a1][a2][a3][a4][a5][a6]=0;
for(auto [i,j]:db){
int nx=a5+i,ny=a6+j;
if(!valid(nx,ny)) continue;
pot[1][a1][a2][a3][a4][a5][a6]++;
}
}
}
if(pot[0][str[0].first][str[0].second][str[1].first][str[1].second][str[2].first][str[2].second]==0){
cout << "Black 0\n";
continue;
}
if(pot[1][str[0].first][str[0].second][str[1].first][str[1].second][str[2].first][str[2].second]==0){
cout << "Red 1\n";
continue;
}
for(int a1=0; a1<n; a1++) for(int a2=0; a2<m; a2++) for(int a3=0; a3<n; a3++){
for(int a4=0; a4<m; a4++) for(int a6=0; a6<m; a6++){
if(!(valid(a1,a2)&&valid(a3,a4)&&valid(0,a6))) continue;
q.push({{1,0},0,{a1,a2},{a3,a4},{0,a6}});
ans[0][a1][a2][a3][a4][0][a6]={1,0};
pot[0][a1][a2][a3][a4][0][a6]=0;
}
}
for(int a1=0; a1<n; a1++) for(int a2=0; a2<m; a2++) for(int a3=0; a3<n; a3++){
for(int a4=0; a4<m; a4++){
if(!(valid(a1,a2)&&valid(a3,a4))) continue;
q.push({{1,0},0,{a1,a2},{a3,a4},{a1,a2}});
ans[0][a1][a2][a3][a4][a1][a2]={1,0};
pot[0][a1][a2][a3][a4][a1][a2]=0;
q.push({{1,0},0,{a1,a2},{a3,a4},{a3,a4}});
ans[0][a1][a2][a3][a4][a3][a4]={1,0};
pot[0][a1][a2][a3][a4][a3][a4]=0;
q.push({{0,0},1,{a1,a2},{a3,a4},{a1,a2}});
ans[1][a1][a2][a3][a4][a1][a2]={0,0};
pot[1][a1][a2][a3][a4][a1][a2]=0;
q.push({{0,0},1,{a1,a2},{a3,a4},{a3,a4}});
ans[1][a1][a2][a3][a4][a3][a4]={0,0};
pot[1][a1][a2][a3][a4][a3][a4]=0;
}
}
while(!q.empty()){
int who;
pair<int,int> win,r1,r2,b1;
tie(win,who,r1,r2,b1) = q.front();
q.pop();
who^=1;
win.second++;
if(win.first==who){
if(who==0){ //red
for(auto [i,j]:dr){
int nx=r1.first+i,ny=r1.second+j;
if(!valid(nx,ny)) continue;
if(nx==r2.first&&ny==r2.second) continue;
if(pot[who][nx][ny][r2.first][r2.second][b1.first][b1.second]!=0){
pot[who][nx][ny][r2.first][r2.second][b1.first][b1.second]=0;
ans[who][nx][ny][r2.first][r2.second][b1.first][b1.second]=win;
q.push({win,who,{nx,ny},r2,b1});
}
}
for(auto [i,j]:dr){
int nx=r2.first+i,ny=r2.second+j;
if(!valid(nx,ny)) continue;
if(nx==r1.first&&ny==r1.second) continue;
if(pot[who][r1.first][r1.second][nx][ny][b1.first][b1.second]!=0){
pot[who][r1.first][r1.second][nx][ny][b1.first][b1.second]=0;
ans[who][r1.first][r1.second][nx][ny][b1.first][b1.second]=win;
q.push({win,who,r1,{nx,ny},b1});
}
}
}
else{
for(auto [i,j]:db){
int nx=b1.first-i,ny=b1.second-j;
if(!valid(nx,ny)) continue;
if(pot[who][r1.first][r1.second][r2.first][r2.second][nx][ny]!=0){
pot[who][r1.first][r1.second][r2.first][r2.second][nx][ny]=0;
ans[who][r1.first][r1.second][r2.first][r2.second][nx][ny]=win;
q.push({win,who,r1,r2,{nx,ny}});
}
}
}
}
else{ //bad
if(who==0){ //red
for(auto [i,j]:dr){
int nx=r1.first+i,ny=r1.second+j;
if(!valid(nx,ny)) continue;
if(nx==r2.first&&ny==r2.second) continue;
if(pot[who][nx][ny][r2.first][r2.second][b1.first][b1.second]!=0){
pot[who][nx][ny][r2.first][r2.second][b1.first][b1.second]--;
if(pot[who][nx][ny][r2.first][r2.second][b1.first][b1.second]==0){
ans[who][nx][ny][r2.first][r2.second][b1.first][b1.second]=win;
q.push({win,who,{nx,ny},r2,b1});
}
}
}
for(auto [i,j]:dr){
int nx=r2.first+i,ny=r2.second+j;
if(!valid(nx,ny)) continue;
if(nx==r1.first&&ny==r1.second) continue;
if(pot[who][r1.first][r1.second][nx][ny][b1.first][b1.second]!=0){
pot[who][r1.first][r1.second][nx][ny][b1.first][b1.second]--;
if(pot[who][r1.first][r1.second][nx][ny][b1.first][b1.second]==0){
ans[who][r1.first][r1.second][nx][ny][b1.first][b1.second]=win;
q.push({win,who,r1,{nx,ny},b1});
}
}
}
}
else{
for(auto [i,j]:db){
int nx=b1.first-i,ny=b1.second-j;
if(!valid(nx,ny)) continue;
if(pot[who][r1.first][r1.second][r2.first][r2.second][nx][ny]!=0){
pot[who][r1.first][r1.second][r2.first][r2.second][nx][ny]--;
if(pot[who][r1.first][r1.second][r2.first][r2.second][nx][ny]==0){
ans[who][r1.first][r1.second][r2.first][r2.second][nx][ny]=win;
q.push({win,who,r1,r2,{nx,ny}});
}
}
}
}
}
}
if(pot[0][str[0].first][str[0].second][str[1].first][str[1].second][str[2].first][str[2].second]){
cout << "Tie\n";
continue;
}
pair<int,int> ret=ans[0][str[0].first][str[0].second][str[1].first][str[1].second][str[2].first][str[2].second];
if(ret.first==0) cout << "Red ";
else cout << "Black ";
cout << ret.second << '\n';
}
}
詳細信息
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 337ms
memory: 52764kb
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: 311ms
memory: 51692kb
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: 243ms
memory: 49028kb
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: 250ms
memory: 47512kb
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: 553ms
memory: 52552kb
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: 488ms
memory: 53248kb
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: 0
Wrong Answer
time: 3ms
memory: 44840kb
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:
Tie Red 7 Black 0 Black 2 Tie Black 10 Red 1 Tie Black 12 Red 1
result:
wrong answer 1st lines differ - expected: 'Red 5', found: 'Tie'
Test #8:
score: 0
Wrong Answer
time: 3ms
memory: 44516kb
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:
Tie Red 3 Red 9 Red 1 Tie Red 5 Red 1 Black 0 Tie Red 3
result:
wrong answer 1st lines differ - expected: 'Red 3', found: 'Tie'
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 42624kb
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:
Tie Red 5 Tie Black 2 Tie Red 5 Red 1 Tie Black 8 Red 3
result:
wrong answer 1st lines differ - expected: 'Red 5', found: 'Tie'
Test #10:
score: 0
Wrong Answer
time: 507ms
memory: 52528kb
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 Tie Tie Tie Red 9 Red 9 Red 7
result:
wrong answer 5th lines differ - expected: 'Red 9', found: 'Tie'
Test #11:
score: 0
Wrong Answer
time: 513ms
memory: 54740kb
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 Tie Tie Red 9 Red 9 Red 1
result:
wrong answer 6th lines differ - expected: 'Red 9', found: 'Tie'
Test #12:
score: 0
Wrong Answer
time: 544ms
memory: 54568kb
input:
12 10 10 10 ##..##..O. .#........ .#.......# .......... #......... .XO##..... #......... .......... .......... .......... 5 6 #.#### #.#### #.OO## #X#### ###### 10 10 ....###### .######### O...##.### .######### ....###### ####....#. ####.####. ####.O..#. #######.#. ####....#X 10 10 .......... .........
output:
Red 1 Black 2 Tie Tie Red 9 Black 6 Tie Tie Red 3 Tie
result:
wrong answer 3rd lines differ - expected: 'Red 9', found: 'Tie'
Test #13:
score: 0
Wrong Answer
time: 563ms
memory: 54116kb
input:
13 10 10 10 .##...#... .#####..## #..#..#..# #........# #...#.#.#. ....#..... ..#####... ....#..#.. ..##O#.... .X...O##.# 10 10 .##......# ..#..##..O ...#.##... ##..#O..## ..#...#... ###.....#X ..#....... .##.#.#... .#.#.#..#. #......#.# 10 10 .........# .......... O......... .......... ....O..... ....
output:
Black 6 Red 9 Red 9 Tie Black 8 Tie Red 7 Red 7 Tie Tie
result:
wrong answer 4th lines differ - expected: 'Red 9', found: 'Tie'
Test #14:
score: 0
Wrong Answer
time: 830ms
memory: 55136kb
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 Tie Black 12 Tie Black 16 Red 5
result:
wrong answer 6th lines differ - expected: 'Red 63', found: 'Tie'
Test #15:
score: 0
Wrong Answer
time: 369ms
memory: 49496kb
input:
15 10 10 10 .########O .........# ########.# .........# .######### .......... #########. .......... .######### .......O.X 10 10 .##...#... .#####..## ...#..##.# #........# #...#.#.#. ....#..... ..#####... ....#..#.. ..##O#.... .X...O##.# 10 8 ####.... ...#..#. .###..#. ...#.O#. ##.#..#. ...####. .##...
output:
Black 102 Black 6 Red 13 Tie Tie Tie Tie Red 139 Tie Black 44
result:
wrong answer 4th lines differ - expected: 'Red 9', found: 'Tie'
Test #16:
score: 0
Wrong Answer
time: 377ms
memory: 50168kb
input:
16 10 10 10 ....###### .######### O...##.### .######### ....###### ####....#. ####.####. ####.O..#. #######.#. ####....#X 10 10 .#..O...#. ...####... ##.X....## .......... .#.O..#... .#....#... .#....#... ..####.... .......... .......... 10 10 O######### #..#..#... ..#..#..## .#..#..#.. ...#..#..# ....
output:
Tie Tie Black 50 Red 333 Red 41 Black 6 Red 133 Black 24 Tie Red 101
result:
wrong answer 1st lines differ - expected: 'Red 9', found: 'Tie'
Test #17:
score: 0
Wrong Answer
time: 547ms
memory: 52664kb
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 Tie Red 67 Tie Tie
result:
wrong answer 7th lines differ - expected: 'Red 9', found: 'Tie'
Test #18:
score: 0
Wrong Answer
time: 405ms
memory: 52900kb
input:
18 10 10 10 O......... #..#..###. .#.##...#. ..X....... .####..... .##...##.# ...#..###. ...###..O# ..#..#.... .......### 10 10 ...#.....O ........#. ........X. .......... ...#...... .......... .........# .....O.... ..#....... .......... 10 10 ..O.#..... #.#...#... ...#..###. ....#..... ..#..#..#. #...
output:
Tie Tie Red 73 Black 36 Black 56 Black 6 Tie Black 0 Tie Black 2
result:
wrong answer 1st lines differ - expected: 'Red 159', found: 'Tie'
Test #19:
score: 0
Wrong Answer
time: 404ms
memory: 52160kb
input:
19 10 10 10 .....#.... ...#.#.#.# #..#.##.#. .##.....#. .#..##.#.# ...#...... #.#.#.##.. ##...#O##. ..#.#O.... .#...#..X. 10 10 .O....#... .####....# .###...#.. .......... ###....##. ....#..##. .#.#.#.... .##.O#..#. #..#...#.. ...#....X# 10 10 O######### #..#..#... ..#..#..## .#..#..#.. ...#..#..# ....
output:
Black 6 Red 57 Black 50 Tie Tie Red 129 Red 99 Black 0 Tie Red 27
result:
wrong answer 4th lines differ - expected: 'Red 11', found: 'Tie'
Test #20:
score: 0
Wrong Answer
time: 397ms
memory: 48792kb
input:
20 10 10 10 .##.....## ...#....## .#.#...#.. .O###..... ###....... ......###. .....#..O. ##........ ..#...X... .##....... 10 10 #...#.##.. .O##.....# #.#.....#. .#...#.... ....#..#.. .###...... ....O##.#. .#.#.....# .......... .#.#...X#. 10 10 ......###. ..#.#..##. .#.......# .#.#..###. ..#.#..#.. #...
output:
Tie Tie Tie Tie Black 6 Black 0 Tie Red 333 Red 57 Tie
result:
wrong answer 2nd lines differ - expected: 'Red 63', found: 'Tie'