Submission #39371279


Source Code Expand

Copy
from collections import defaultdict
N = int(input())
S = input()
move = {
"R": lambda x, y: (x + 1, y),
"L": lambda x, y: (x - 1, y),
"U": lambda x, y: (x, y + 1),
"D": lambda x, y: (x, y - 1),
}
now = (0, 0)
points = defaultdict(int, {now: 1})
for c in S:
nxt = move[c](*now)
if points[nxt]:
print("Yes")
break
else:
points[nxt] += 1
now = nxt
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
from collections import defaultdict

N = int(input())
S = input()

move = {
  "R": lambda x, y: (x + 1, y),
  "L": lambda x, y: (x - 1, y),
  "U": lambda x, y: (x, y + 1),
  "D": lambda x, y: (x, y - 1),
}
now = (0, 0)
points = defaultdict(int, {now: 1})
for c in S:
  nxt = move[c](*now)
  if points[nxt]:
    print("Yes")
    break
  else:
    points[nxt] += 1
    now = nxt
else:
  print("No")

Submission Info

Submission Time
Task C - LRUD Instructions 2
User arakaki_tokyo
Language Python (3.8.2)
Score 300
Code Size 418 Byte
Status AC
Exec Time 168 ms
Memory 41480 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand.txt, hand_01.txt, hand_02.txt, min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand.txt AC 162 ms 41344 KB
hand_01.txt AC 158 ms 41224 KB
hand_02.txt AC 78 ms 19480 KB
min.txt AC 18 ms 9112 KB
random_01.txt AC 24 ms 9500 KB
random_02.txt AC 23 ms 9404 KB
random_03.txt AC 20 ms 9488 KB
random_04.txt AC 23 ms 9464 KB
random_05.txt AC 28 ms 9528 KB
random_06.txt AC 21 ms 9408 KB
random_07.txt AC 163 ms 41428 KB
random_08.txt AC 64 ms 17312 KB
random_09.txt AC 162 ms 41480 KB
random_10.txt AC 56 ms 17108 KB
random_11.txt AC 168 ms 41340 KB
random_12.txt AC 40 ms 12872 KB
random_13.txt AC 21 ms 9532 KB
random_14.txt AC 24 ms 9404 KB
random_15.txt AC 23 ms 9512 KB
random_16.txt AC 21 ms 9384 KB
random_17.txt AC 20 ms 9392 KB
random_18.txt AC 26 ms 9404 KB
random_19.txt AC 20 ms 9500 KB
random_20.txt AC 25 ms 9396 KB
random_21.txt AC 20 ms 9404 KB
random_22.txt AC 25 ms 9620 KB
random_23.txt AC 153 ms 41220 KB
random_24.txt AC 160 ms 41224 KB
random_25.txt AC 155 ms 41232 KB
random_26.txt AC 164 ms 41228 KB
random_27.txt AC 159 ms 41468 KB
random_28.txt AC 165 ms 41332 KB
random_29.txt AC 160 ms 41332 KB
random_30.txt AC 163 ms 41352 KB
random_31.txt AC 154 ms 41352 KB
random_32.txt AC 111 ms 27692 KB
sample_01.txt AC 20 ms 9112 KB
sample_02.txt AC 20 ms 9308 KB


2025-04-05 (Sat)
20:01:50 +00:00