Submission #30058021


Source Code Expand

Copy
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
public class Main {
private static final char UP = 'U';
private static final char LEFT = 'L';
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) {
int n = scanner.nextInt();
BigInteger x = new BigInteger(scanner.next()), two = BigInteger.valueOf(2L);
char[] s = scanner.next().toCharArray();
Deque<Character> que = new ArrayDeque<>();
for (int i = 0; i < n; i++) {
if (UP == s[i]) {
if (que.isEmpty()) {
x = x.divide(two);
} else {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	private static final char UP = 'U';
	private static final char LEFT = 'L';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			BigInteger x = new BigInteger(scanner.next()), two = BigInteger.valueOf(2L);
			char[] s = scanner.next().toCharArray();
			Deque<Character> que = new ArrayDeque<>();
			for (int i = 0; i < n; i++) {
				if (UP == s[i]) {
					if (que.isEmpty()) {
						x = x.divide(two);
					} else {
						que.pollLast();
					}
				} else {
					que.addLast(s[i]);
				}
			}
			while (!que.isEmpty()) {
				char c = que.poll();
				if (LEFT == c) {
					x = x.multiply(two);
				} else {
					x = x.multiply(two).add(BigInteger.ONE);
				}
			}
			System.out.println(x);
		}
	}
}

Submission Info

Submission Time
Task D - Moves on Binary Tree
User danielsun3164
Language Java (OpenJDK 11.0.6)
Score 400
Code Size 941 Byte
Status AC
Exec Time 311 ms
Memory 59396 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 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, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 291 ms 48360 KB
random_02.txt AC 225 ms 43088 KB
random_03.txt AC 281 ms 48732 KB
random_04.txt AC 208 ms 43244 KB
random_05.txt AC 288 ms 48492 KB
random_06.txt AC 261 ms 47432 KB
random_07.txt AC 277 ms 48640 KB
random_08.txt AC 289 ms 48276 KB
random_09.txt AC 271 ms 48328 KB
random_10.txt AC 238 ms 43376 KB
random_11.txt AC 281 ms 48736 KB
random_12.txt AC 278 ms 47508 KB
random_13.txt AC 289 ms 59168 KB
random_14.txt AC 299 ms 59228 KB
random_15.txt AC 287 ms 59196 KB
random_16.txt AC 302 ms 59308 KB
random_17.txt AC 293 ms 59120 KB
random_18.txt AC 291 ms 58948 KB
random_19.txt AC 293 ms 59140 KB
random_20.txt AC 302 ms 59284 KB
random_21.txt AC 302 ms 59396 KB
random_22.txt AC 286 ms 59288 KB
random_23.txt AC 311 ms 59308 KB
random_24.txt AC 300 ms 58852 KB
sample_01.txt AC 109 ms 35812 KB
sample_02.txt AC 111 ms 35768 KB
sample_03.txt AC 115 ms 35760 KB


2025-02-28 (Fri)
05:08:26 +00:00