QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#853110#9926. Flipping Pathsruoye123456AC ✓184ms16160kbPython34.0kb2025-01-11 15:47:362025-01-11 15:47:37

Judging History

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

  • [2025-01-11 15:47:37]
  • 评测
  • 测评结果:AC
  • 用时:184ms
  • 内存:16160kb
  • [2025-01-11 15:47:36]
  • 提交

answer

# Import required libraries
from typing import List, Tuple
from dataclasses import dataclass

# Constants
N = 2_000_010  # Equivalent to 2e6+10 in C++
MAX_SIZE = 314  # Size for 2D arrays
MAX_ANS = 410  # Size for answer arrays

# Global variables
n = m = idx = 0
a = [[0] * MAX_SIZE for _ in range(MAX_SIZE)]  # Main grid
b = [[0] * MAX_SIZE for _ in range(MAX_SIZE)]  # Backup grid
ans = [[] for _ in range(MAX_ANS)]  # Store paths

def check() -> bool:
    """
    Check if current configuration is valid and construct paths
    Returns: True if valid solution found, False otherwise
    """
    global idx
    idx = 0
    now = []  # List of (position, index) pairs
    
    # Process first row
    for j in range(m-1, -1, -1):
        if a[0][j] == 1:
            idx += 1
            ans[idx].append(0)
            ans[idx].append(j)
            # Flip bits
            for i in range(j+1):
                a[0][i] ^= 1
            now.append((j, idx))
    
    # Process middle rows
    for i in range(1, n-1):
        # Apply previous operations
        for x, y in now:
            a[i][x] ^= 1
            
        now.sort(reverse=True)  # Sort by position descending
        p = 0
        nw = []  # New operations
        
        # Process current row
        for j in range(m-1, 0, -1):
            if a[i][j] == 0:
                continue
                
            # Apply pending operations
            while p < len(now) and now[p][0] >= j:
                nw.append(now[p])
                ans[now[p][1]].append(now[p][0])
                p += 1
                
            # Add new operations if needed
            if p >= len(now):
                idx += 1
                for k in range(i+1):
                    ans[idx].append(0)
                now.append((0, idx))
                idx += 1
                for k in range(i+1):
                    ans[idx].append(0)
                now.append((0, idx))
            
            # Flip bits
            for k in range(now[p][0]+1, j+1):
                a[i][k] ^= 1
            now[p] = (j, now[p][1])
            ans[now[p][1]].append(j)
            nw.append(now[p])
            p += 1
        
        # Check if first column is valid
        if a[i][0]:
            return False
            
        # Add remaining operations
        while p < len(now):
            nw.append(now[p])
            ans[now[p][1]].append(now[p][0])
            p += 1
            
        now = nw
    
    # Process last row
    for x, y in now:
        for i in range(x, m):
            a[n-1][i] ^= 1
        ans[y].append(m-1)
    
    # Verify final state
    for i in range(n):
        for j in range(m):
            if a[i][j]:
                return False
    
    # Output solution
    print("YES")
    print(idx)
    assert idx <= n + m
    
    # Construct and output paths
    for i in range(1, idx+1):
        s = ""
        for j in range(1, len(ans[i])):
            s += "R" * (ans[i][j] - ans[i][j-1])
            if j != len(ans[i])-1:
                s += "D"
        print(s)
        assert len(s) == n + m - 2
        
    return True

def solve() -> None:
    """
    Main solving function for each test case
    """
    global n, m
    n, m = map(int, input().split())
    
    # Read input grid
    for i in range(n):
        s = input()
        for j in range(m):
            b[i][j] = 1 if s[j] == 'W' else 0
    
    # Try original configuration
    for i in range(n):
        for j in range(m):
            a[i][j] = b[i][j]
    
    for i in range(MAX_ANS):
        ans[i].clear()
    
    if check():
        return
    
    # Try inverted configuration
    for i in range(n):
        for j in range(m):
            b[i][j] ^= 1
            a[i][j] = b[i][j]
    
    for i in range(MAX_ANS):
        ans[i].clear()
    
    if check():
        return
    
    print("NO")

# Main execution
t = int(input())  # Number of test cases
for _ in range(t):
    solve()

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 38ms
memory: 14808kb

input:

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

output:

YES
2
RRDD
DDRR
YES
0
YES
0
NO

result:

ok ok (4 test cases)

Test #2:

score: 0
Accepted
time: 36ms
memory: 14580kb

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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YES
2
RRDR
DRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRRD
RRDR
DRR...

result:

ok ok (278 test cases)

Test #4:

score: 0
Accepted
time: 46ms
memory: 14508kb

input:

333
3 3
BBW
WWB
BWB
3 3
BBW
WWB
BWW
3 3
BBW
WWB
WBB
3 3
BBW
WWB
WBW
3 3
BBW
WWB
WWB
3 3
BBW
WWB
WWW
3 3
BBW
WWW
BBB
3 3
BBW
WWW
BBW
3 3
BBW
WWW
BWB
3 3
BBW
WWW
BWW
3 3
BBW
WWW
WBB
3 3
BBW
WWW
WBW
3 3
BBW
WWW
WWB
3 3
BBW
WWW
WWW
3 3
BWB
BBB
BBB
3 3
BWB
BBB
BBW
3 3
BWB
BBB
BWB
3 3
BWB
BBB
BWW
3 3
BWB
...

output:

YES
3
RDRD
DRDR
DDRR
NO
NO
NO
NO
NO
YES
3
RDDR
DRDR
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRDD
RDDR
DDRR
NO
NO
NO
NO
NO
YES
3
RRDD
RDRD
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRDD
RDDR
DRDR
NO
NO
NO
NO
NO
YES
3
RRDD
RDRD
DRDR
NO
NO
NO
YES
2
RDDR
DRDR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
RDRD
...

result:

ok ok (333 test cases)

Test #5:

score: 0
Accepted
time: 44ms
memory: 14488kb

input:

266
3 3
WWB
WWW
WWW
3 3
WWW
BBB
BBB
3 3
WWW
BBB
BBW
3 3
WWW
BBB
BWB
3 3
WWW
BBB
BWW
3 3
WWW
BBB
WBB
3 3
WWW
BBB
WBW
3 3
WWW
BBB
WWB
3 3
WWW
BBB
WWW
3 3
WWW
BBW
BBB
3 3
WWW
BBW
BBW
3 3
WWW
BBW
BWB
3 3
WWW
BBW
BWW
3 3
WWW
BBW
WBB
3 3
WWW
BBW
WBW
3 3
WWW
BBW
WWB
3 3
WWW
BBW
WWW
3 3
WWW
BWB
BBB
3 3
WWW
...

output:

NO
NO
NO
NO
YES
3
RRDD
DRRD
DRDR
NO
NO
NO
NO
NO
YES
1
RRDD
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
3
RRDD
DRRD
DDRR
NO
NO
NO
NO
NO
YES
3
RRDD
DRDR
DDRR
NO
NO
NO
YES
2
DRRD
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
DRDR
DDRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
DRRD
DRDR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
0
Y...

result:

ok ok (266 test cases)

Test #6:

score: 0
Accepted
time: 28ms
memory: 14592kb

input:

245
4 2
WW
BB
WB
BW
4 2
WW
BB
WB
WB
4 2
WW
BB
WB
WW
4 2
WW
BB
WW
BB
4 2
WW
BB
WW
BW
4 2
WW
BB
WW
WB
4 2
WW
BB
WW
WW
4 2
WW
BW
BB
BB
4 2
WW
BW
BB
BW
4 2
WW
BW
BB
WB
4 2
WW
BW
BB
WW
4 2
WW
BW
BW
BB
4 2
WW
BW
BW
BW
4 2
WW
BW
BW
WB
4 2
WW
BW
BW
WW
4 2
WW
BW
WB
BB
4 2
WW
BW
WB
BW
4 2
WW
BW
WB
WB
4 2
WW
B...

output:

NO
NO
YES
3
RDDD
DRDD
DDDR
NO
YES
3
RDDD
DRDD
DDRD
NO
NO
NO
NO
NO
YES
3
RDDD
DDRD
DDDR
NO
YES
1
RDDD
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
DRDD
DDDR
NO
NO
NO
NO
NO
YES
2
DRDD
DDRD
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
2
DDRD
DDDR
NO
NO
NO
NO
NO
YES
0
YES
0
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok ok (245 test cases)

Test #7:

score: 0
Accepted
time: 36ms
memory: 14500k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
RRDRDDD
DDRRDRD
DDRDRDR
DDDDRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
RRDRDDD
DDRRDDR
DDRDRDR
DDDDRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
4
RRDRDDD
DDRRDRD
DDRDDRR
DDDDRRR
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok ok (200 test cases)

Test #9:

score: 0
Accepted
time: 172ms
memory: 16160kb

input:

5
200 200
WBWWWBWBWWWWBWWWBBBBBBWBWWBWWBBWBWWBWBBBWBBWBBWBWBBWWWWWWBWWWBBWBWBWBWBBWBWWBWWBWBBBWWWBWBBWWBBBBBWWBBBBWWBBWBWWWBBWBWBWWWWBBWBWWBWWWWWBWWBBBBBWBBWBWWWWWBWWWBWBWWBBBBWWBWWWWBWBBWBWBBWWBWWBBWBWBWWBWBWB
BBWBBBBBWBWWWWWWWWWWBBWWWWBWWBWWBBBBBWWWBWBWWBBWBBWWBBBBBWWBWBWBWWBWBWBBBBWWWWBWBBBBBWBBB...

output:

YES
358
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

result:

ok ok (5 test cases)

Test #10:

score: 0
Accepted
time: 184ms
memory: 15928kb

input:

5
200 200
WBWBWWBBBWWWWBWWWBBBBWWWWBWWBBBBWWBWWWWBWWBWWBWBBWBWWWWWWBBBWWWBWBBWBBBBBBWBBBWW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RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDDDDDDDDDDDDDDDDRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD...

result:

ok ok (5 test cases)

Test #12:

score: 0
Accepted
time: 123ms
memory: 15560kb

input:

8
156 104
WWWBWWWBWBWBWWBWBWWBBBWBWWWBBWWBBWWWBBWWBBBBWBWWWWBWBBBBBWWWBBWBBWBBBWBWWBWWBWWBBWBWBWBWBBWWBWWWWBBBWBBW
WBBWWBBWWBWBWWBWWBBWBBWBWWWWWWWWWBBWBBBBWWBBBBWBBBBWBBWWBBBWWWBWWWWBBWWWBWBWWBWBBWWWWBBBWWBBWWWBBWWBBWWW
BBBWBBBWWWBBBBWBBWBBWWBWWBBWBBWWWBWWBBBBWBBWWWBBWWWBBBBBBBBBBBWWWBBWBWWWWBWBBWWW...

output:

YES
224
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDDDRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

result:

ok ok (8 test cases)

Test #13:

score: 0
Accepted
time: 119ms
memory: 15940kb

input:

5
114 120
BWWBBWWWWBWBBWWBWBBBBWBWWBBBWBWBWBWBWWBWWBWWWBBWBBBBBWBBBBBWWWBWWBBBWBWWBBBBBWWBWBBWBBBWBWBWBBWWBWBWWWWBWWWBBBWBWWWBWBBB
WBWWWBBBBBBBWBBBWWBWWWWWBWWBWWBBBBBBBWBBBWBWBWBBBBWBWBBWB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RRRRRRRRRDDDDDDDDDDRDDDDDDDDDDDDDDDDDD...

result:

ok ok (100 test cases)

Test #15:

score: 0
Accepted
time: 49ms
memory: 15016kb

input:

50
1 14
BBBBBBBBBBBBBB
15 3
WWW
WBB
BBB
WWB
BBB
WBB
WWW
BBW
BWB
WBW
WWW
WBB
BBB
WWB
BBW
3 19
WBWBBBWWBBWBWBWBBWB
BBBWWWBWBBWWBBWBBWW
BWBBWBBWBBWWBBWBBWW
77 21
WWWBBBBBWBWBWBWWWWWWW
WBBWBBBWWBBWBWBWWWWBW
BBBWBWWWWWWWWBWBWBBBW
BWBBBWBWWWWBBBWBBBBWW
WBBWWWBWWBWWBWWBBBBWB
WWWBBBWBBWBBBBBBWBWBB
BWWWWWBWW...

output:

YES
0
YES
10
DRRDDDDDDDDDDDDD
DDRDDDDDDDDDDDDR
DDDRDDDDDDDDRDDD
DDDDRDDRDDDDDDDD
DDDDDDRDDRDDDDDD
DDDDDDDDRDRDDDDD
DDDDDDDDDDDRDDDR
DDDDDDDDDDDDRDDR
DDDDDDDDDDDDDRDR
DDDDDDDDDDDDDDRR
YES
16
RRRRRRRRRRRRRRRRRRDD
RRRRRRRRRRRRRRRRRDRD
RRRRRRRRRRRRRRRRDRDR
RRRRRRRRRRRRRRDRDRRR
RRRRRRRRRRRRRDRDRRRR
RRRRR...

result:

ok ok (50 test cases)

Test #16:

score: 0
Accepted
time: 89ms
memory: 16008kb

input:

10
2 23
BBWWBBWWWBWBWBBWBBBWWBW
BWWBBWWWBWBWBBWBBBWWBWB
87 44
BBWBWBWBWWWWWWBWWBBBWBBBBWWWWBBBBBBWBWWWWBWW
BBWBBBWBWBWBBWWBBBWWBWWWWBWBBBBWWWWBBBBBWBWW
WBWBBWBWBBBWBWWWBBBBWWBWBWWBWBWWWWWBBBWWBBWB
WBWWWWWWBWWWBBBBBWBBBWBBWWWBBBBBBBWWWWWWWWWB
BWBWWBBWBBBBBBBBWBBBWBBWWBBBBBWBWBWBBWWBWBWW
BBBWBBBBBBWWB...

output:

YES
14
RRRRRRRRRRRRRRRRRRRRRRD
RRRRRRRRRRRRRRRRRRRRRDR
RRRRRRRRRRRRRRRRRRRRDRR
RRRRRRRRRRRRRRRRRRDRRRR
RRRRRRRRRRRRRRRDRRRRRRR
RRRRRRRRRRRRRRDRRRRRRRR
RRRRRRRRRRRRDRRRRRRRRRR
RRRRRRRRRRRDRRRRRRRRRRR
RRRRRRRRRRDRRRRRRRRRRRR
RRRRRRRRRDRRRRRRRRRRRRR
RRRRRRRRDRRRRRRRRRRRRRR
RRRRRDRRRRRRRRRRRRRRRRR
RRRDR...

result:

ok ok (10 test cases)

Extra Test:

score: 0
Extra Test Passed