QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#835824#9926. Flipping Pathsucup-team112#WA 17ms10744kbPython32.9kb2024-12-28 14:51:032024-12-28 14:51:04

Judging History

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

  • [2024-12-28 14:51:04]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:10744kb
  • [2024-12-28 14:51:03]
  • 提交

answer


"""

"""

import sys
from sys import stdin

TT = int(stdin.readline())

def solve(c,want):

    n = len(c)
    m = len(c[0])

    c_copy = [[ c[i][j] for j in range(m) ] for i in range(n)]
    c = c_copy

    ans = []

    # 右上
    for imj in range(-(m-1),0):
        x,y = 0,0
        route = []

        c[x][y] ^= 1
        while x-y != imj+1:
            route.append( "R" )
            y += 1
            c[x][y] ^= 1

        while x != n-1 and y != m-1:
            if c[x][y+1] != want:
                route.append("R")
                y += 1
                c[x][y] ^= 1
                route.append("D")
                x += 1
                c[x][y] ^= 1
            else:
                route.append("D")
                x += 1
                c[x][y] ^= 1
                route.append("R")
                y += 1
                c[x][y] ^= 1

        while x != n-1:
            route.append("D")
            x += 1
            c[x][y] ^= 1

        while y != m-1:
            route.append("R")
            y += 1
            c[x][y] ^= 1

        ans.append(route)

    # 左下
    for imj in range(n-1,0,-1):
        x,y = 0,0
        route = []

        c[x][y] ^= 1
        while x-y != imj-1:
            route.append( "D" )
            x += 1
            c[x][y] ^= 1

        while x != n-1 and y != m-1:
            if c[x+1][y] != want:
                route.append("D")
                x += 1
                c[x][y] ^= 1
                route.append("R")
                y += 1
                c[x][y] ^= 1
            else:
                route.append("R")
                y += 1
                c[x][y] ^= 1
                route.append("D")
                x += 1
                c[x][y] ^= 1

        while x != n-1:
            route.append("D")
            x += 1
            c[x][y] ^= 1

        while y != m-1:
            route.append("R")
            y += 1
            c[x][y] ^= 1

        ans.append(route)

    flag = True
    for i in range(n):
        for j in range(m):
            if c[0][0] != c[i][j]:
                flag = False

    # print (c,ans)
    if flag:
        return ans
    else:
        return None

for loop in range(TT):

    n,m = map(int,stdin.readline().split())

    c = [list(stdin.readline()[:-1]) for i in range(n)]

    for i in range(n):
        for j in range(m):
            if c[i][j] == "B":
                c[i][j] = 1
            else:
                c[i][j] = 0

    
    ans1 = solve(c,0)
    if ans1 != None:
        print ("YES")
        print (len(ans1))
        for cs in ans1:
            print ("".join(cs))
        continue

    ans2 = solve(c,1)
    if ans2 != None:
        print ("YES")
        print (len(ans2))
        for cs in ans2:
            print ("".join(cs))
        continue

    print ("NO")
        

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 10744kb

input:

4
3 3
WBB
BWB
BBW
1 5
WWWWW
2 2
BB
BB
4 1
W
B
B
W

output:

YES
4
RRDD
DRDR
DDRR
DRDR
YES
4
RRRR
RRRR
RRRR
RRRR
YES
2
DR
DR
NO

result:

ok ok (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 10620kb

input:

323
1 2
BB
1 2
BW
1 2
WB
1 2
WW
2 1
B
B
2 1
B
W
2 1
W
B
2 1
W
W
1 3
BBB
1 3
BBW
1 3
BWB
1 3
BWW
1 3
WBB
1 3
WBW
1 3
WWB
1 3
WWW
2 2
BB
BB
2 2
BB
BW
2 2
BB
WB
2 2
BB
WW
2 2
BW
BB
2 2
BW
BW
2 2
BW
WB
2 2
BW
WW
2 2
WB
BB
2 2
WB
BW
2 2
WB
WB
2 2
WB
WW
2 2
WW
BB
2 2
WW
BW
2 2
WW
WB
2 2
WW
WW
3 1
B
B
B
3 ...

output:

YES
1
R
NO
NO
YES
1
R
YES
1
D
NO
NO
YES
1
D
YES
2
RR
RR
NO
NO
NO
NO
NO
NO
YES
2
RR
RR
YES
2
DR
DR
NO
NO
NO
NO
NO
YES
2
RD
DR
NO
NO
YES
2
RD
DR
NO
NO
NO
NO
NO
YES
2
DR
DR
YES
2
DD
DD
NO
NO
NO
NO
NO
NO
YES
2
DD
DD
YES
3
RRR
RRR
RRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRR
RRR
RRR
NO
NO
NO
N...

result:

wrong answer Jury has answer but participant has not. (test case 19)