QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#511025#6314. 过河卒bribritt100 ✓1366ms104712kbC++142.6kb2024-08-09 15:18:072024-08-09 15:18:07

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 15:18:07]
  • 评测
  • 测评结果:100
  • 用时:1366ms
  • 内存:104712kb
  • [2024-08-09 15:18:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define REP(i,n) for(int i=0;i<n;++i)
void solvetc(int n, int m, vector<string> s) {
	vector<vector<int>> adjR(2*n*n*n*m*m*m);
	vector<int> dx={0,-1,0,1}, dy={1,0,-1,0};
	auto val = [n,m,&s](int bx, int by, int rx0, int ry0, int rx1, int ry1) {
		if(min({bx,by,rx0,ry0,rx1,ry1})<0||max({bx,rx0,rx1})>=n||max({by,ry0,ry1})>=m) return 0;
		if(s[bx][by]=='#'||s[rx0][ry0]=='#'||s[rx1][ry1]=='#') return 0;
		if(rx0==rx1&&ry0==ry1) return 0;
		return 1;
	};
	auto lost = [](int bx, int by, int rx0, int ry0, int rx1, int ry1) {
		if(!bx) return 1;
		if(bx==rx0&&by==ry0) return 1;
		if(bx==rx1&&by==ry1) return 1;
		return 0;
	};
	auto posId = [n,m](int bx, int by, int rx0, int ry0, int rx1, int ry1, bool redTurn) {
		if(make_pair(rx0,ry0)>make_pair(rx1,ry1)) {swap(rx0,rx1);swap(ry0,ry1);}
		return 2*(bx*n*n*m*m*m+by*n*n*m*m+rx0*n*m*m+ry0*n*m+rx1*m+ry1)+redTurn;
	};
	REP(bx,n) REP(by,m) REP(rx0,n) REP(ry0,m) REP(rx1,n) REP(ry1,m) if(val(bx,by,rx0,ry0,rx1,ry1)&&!lost(bx,by,rx0,ry0,rx1,ry1)&&make_pair(rx0,ry0)<make_pair(rx1,ry1)) {
		int cur = posId(bx,by,rx0,ry0,rx1,ry1,0);
		REP(i,3) if(val(bx+dx[i],by+dy[i],rx0,ry0,rx1,ry1)) adjR[posId(bx+dx[i],by+dy[i],rx0,ry0,rx1,ry1,1)].push_back(cur);
		REP(i,4) if(val(bx,by,rx0+dx[i],ry0+dy[i],rx1,ry1)) adjR[posId(bx,by,rx0+dx[i],ry0+dy[i],rx1,ry1,0)].push_back(cur+1);
		REP(i,4) if(val(bx,by,rx0,ry0,rx1+dx[i],ry1+dy[i])) adjR[posId(bx,by,rx0,ry0,rx1+dx[i],ry1+dy[i],0)].push_back(cur+1);
	}
	vector<int> deg(2*n*n*n*m*m*m,0);
	REP(i,2*n*n*n*m*m*m) for(auto j: adjR[i]) ++deg[j];
	stack<int> loss, win;
	vector<int> st(2*n*n*n*m*m*m,-1);
	REP(i,2*n*n*n*m*m*m) if(!deg[i]) {st[i]=-1e9;if(adjR[i].size())loss.push(i);}
	while(loss.size()||win.size()) {
		while(loss.size()) {
			int x = loss.top(); loss.pop();
			for(auto i: adjR[x]) if(st[i]<~st[x]) {
				st[i]=~st[x];
				win.push(i);
			}
		}
		while(win.size()) {
			int x = win.top(); win.pop();
			for(auto i: adjR[x]) {
				st[i] = max(st[i],1000000001-st[x]);
				deg[i]--;
				if(!deg[i] && st[i]<5e8) st[i]-=1e9, loss.push(i);
			}
		}
	}
	int bx, by, rx0=-1, ry0, rx1, ry1;
	for(int i=0;i<n;++i) for(int j=0;j<m;++j) {
		if(s[i][j]=='X') bx=i,by=j;
		if(s[i][j]=='O') {
			if(rx0==-1) rx0=i, ry0=j;
			else rx1=i, ry1=j;
		}
	}
	int ans = st[posId(bx,by,rx0,ry0,rx1,ry1,1)];
	if(ans<-1) cout<<"Black "<<ans+1e9<<"\n";
	else if(ans>5e8) cout<<"Red "<<1e9-ans<<"\n";
	else cout<<"Tie\n";
}
main() {
	int id, T; cin >> id >> T;
	while(T--) {
		int n, m; cin >> n >> m;
		vector<string> s(n); for(int i=0;i<n;++i) cin>>s[i];
		solvetc(n,m,s);
	}
}

详细


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 743ms
memory: 97232kb

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: 649ms
memory: 92996kb

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: 662ms
memory: 96044kb

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: 517ms
memory: 79204kb

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: 1001ms
memory: 92144kb

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: 863ms
memory: 92172kb

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: 1ms
memory: 3860kb

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: 0ms
memory: 3952kb

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: 0ms
memory: 3956kb

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: 819ms
memory: 100184kb

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: 926ms
memory: 104712kb

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: 900ms
memory: 100164kb

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: 918ms
memory: 99240kb

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: 1366ms
memory: 102516kb

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: 630ms
memory: 90572kb

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: 647ms
memory: 91532kb

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: 959ms
memory: 99900kb

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: 719ms
memory: 97108kb

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: 773ms
memory: 92872kb

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: 735ms
memory: 81252kb

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