2024 S3 - Swipe

Hardad hoc

1 Solution Available

Solution 1

PYTHON
1# By Oscar Zhou, Abbey Park High School
2# This solution still requires commented explanations. Please feel free to add them!
3
4# https://dmoj.ca/problem/ccc24s3
5
6import sys
7input = sys.stdin.readline
8
9n = int(input())
10arrA = list(map(int, input().split()))
11arrB = list(map(int, input().split()))
12valTrack = [arrB[0]] # value track for array B
13rangeTrack = [] # left, right track for array B
14
15l = 0
16r = 0
17val = arrB[0]
18
19# Array B is segmented
20for i in range(1, n):
21    if arrB[i] == val:
22        r += 1
23    else:
24        rangeTrack.append((l, r))
25        l = i
26        r = i
27        val = arrB[i]
28        valTrack.append(val)
29rangeTrack.append((l, r))
30
31cur = 0
32swipeL = []
33swipeR = []
34for i in range(n):
35    if cur == len(valTrack): break
36    if arrA[i] == valTrack[cur]:
37        if rangeTrack[cur][0] < i:
38            swipeL.append((rangeTrack[cur][0], i))
39        if rangeTrack[cur][1] > i:
40            swipeR.append((i, rangeTrack[cur][1]))
41        cur += 1
42
43if cur == len(valTrack):
44    print("YES")
45    print(len(swipeL) + len(swipeR))
46    for left in swipeL:
47        print("L", left[0], left[1])
48    for i in range(len(swipeR)-1, -1, -1):
49        print("R", swipeR[i][0], swipeR[i][1])
50
51else:
52    print("NO")

Test Cases

Select a test case to view input and output