QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#873932#3445. Numbers On a Treefernandes_queilaAC ✓85ms44664kbJava17993b2025-01-27 09:27:192025-01-27 09:27:21

Judging History

This is the latest submission verdict.

  • [2025-01-27 09:27:21]
  • Judged
  • Verdict: AC
  • Time: 85ms
  • Memory: 44664kb
  • [2025-01-27 09:27:19]
  • Submitted

answer

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine().trim();
        String[] parts = line.split(" ");
        int height = Integer.parseInt(parts[0]);
        String road = parts.length > 1 ? parts[1] : "";
        int result = searchNode(height, road);
        System.out.println(result);
        scanner.close();
    }

    public static int searchNode(int height, String road) {
        int root = (1 << (height + 1)) - 1;

        if (road.isEmpty()) {
            return root;
        }

        int label = root;
        int local = 0;

        for (char move : road.toCharArray()) {
            if (Character.toLowerCase(move) == 'l') {
                local = 2 * local + 1;
            } else if (Character.toLowerCase(move) == 'r') {
                local = 2 * local + 2;
            }
        }

        label -= local;
        return label;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 80ms
memory: 44112kb

input:

3 LR

output:

11

result:

ok single line: '11'

Test #2:

score: 0
Accepted
time: 80ms
memory: 44472kb

input:

3 RRL

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 74ms
memory: 44124kb

input:

2

output:

7

result:

ok single line: '7'

Test #4:

score: 0
Accepted
time: 81ms
memory: 44368kb

input:

3 LRL

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 76ms
memory: 44124kb

input:

26 RRLLLLRRRL

output:

134215922

result:

ok single line: '134215922'

Test #6:

score: 0
Accepted
time: 82ms
memory: 44384kb

input:

13 RLL

output:

16372

result:

ok single line: '16372'

Test #7:

score: 0
Accepted
time: 79ms
memory: 44120kb

input:

27 LLLLRRL

output:

268435322

result:

ok single line: '268435322'

Test #8:

score: 0
Accepted
time: 81ms
memory: 44188kb

input:

3 RLR

output:

3

result:

ok single line: '3'

Test #9:

score: 0
Accepted
time: 82ms
memory: 44104kb

input:

7 RRLLLRL

output:

30

result:

ok single line: '30'

Test #10:

score: 0
Accepted
time: 79ms
memory: 44284kb

input:

22 RRRRRLLRLRRRRRLLLLRRL

output:

4247674

result:

ok single line: '4247674'

Test #11:

score: 0
Accepted
time: 81ms
memory: 44076kb

input:

18 RRLRRRRRLRRRRRR

output:

462913

result:

ok single line: '462913'

Test #12:

score: 0
Accepted
time: 80ms
memory: 44184kb

input:

30 LLR

output:

2147483639

result:

ok single line: '2147483639'

Test #13:

score: 0
Accepted
time: 79ms
memory: 44456kb

input:

25 LLRRLRLLRRRRRRLRRLR

output:

66476051

result:

ok single line: '66476051'

Test #14:

score: 0
Accepted
time: 74ms
memory: 44120kb

input:

20 RLRRLLRLLRLRRLR

output:

2041555

result:

ok single line: '2041555'

Test #15:

score: 0
Accepted
time: 80ms
memory: 44180kb

input:

28 RRLLRLRLLLRLRRRLL

output:

536636324

result:

ok single line: '536636324'

Test #16:

score: 0
Accepted
time: 80ms
memory: 44108kb

input:

14 RLRLRRLLRRL

output:

29338

result:

ok single line: '29338'

Test #17:

score: 0
Accepted
time: 81ms
memory: 44312kb

input:

28 LRLRLLRRRLLRLLL

output:

536827448

result:

ok single line: '536827448'

Test #18:

score: 0
Accepted
time: 77ms
memory: 44204kb

input:

9 L

output:

1022

result:

ok single line: '1022'

Test #19:

score: 0
Accepted
time: 76ms
memory: 44664kb

input:

2

output:

7

result:

ok single line: '7'

Test #20:

score: 0
Accepted
time: 79ms
memory: 44308kb

input:

3

output:

15

result:

ok single line: '15'

Test #21:

score: 0
Accepted
time: 79ms
memory: 44388kb

input:

30 RRR

output:

2147483633

result:

ok single line: '2147483633'

Test #22:

score: 0
Accepted
time: 80ms
memory: 44416kb

input:

30 LRRLLLLLLLLRR

output:

2147472381

result:

ok single line: '2147472381'

Test #23:

score: 0
Accepted
time: 85ms
memory: 44348kb

input:

30 LRRLRRLRL

output:

2147482918

result:

ok single line: '2147482918'

Test #24:

score: 0
Accepted
time: 80ms
memory: 44008kb

input:

30 RRRRRLRRLRLRRRRRRLRLRLLL

output:

2114232408

result:

ok single line: '2114232408'

Test #25:

score: 0
Accepted
time: 79ms
memory: 44336kb

input:

30 RRRRRRLLRRRRR

output:

2147467361

result:

ok single line: '2147467361'

Test #26:

score: 0
Accepted
time: 81ms
memory: 44076kb

input:

30 LRLLRRRLLLLRRRRRLRLRRRRLRR

output:

2059895429

result:

ok single line: '2059895429'

Test #27:

score: 0
Accepted
time: 77ms
memory: 44456kb

input:

30 LRLLRRRLLLLRRRRRLRLRRRRLRRRLRR

output:

746072133

result:

ok single line: '746072133'

Test #28:

score: 0
Accepted
time: 75ms
memory: 44352kb

input:

30 RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

output:

1

result:

ok single line: '1'

Test #29:

score: 0
Accepted
time: 81ms
memory: 44016kb

input:

30

output:

2147483647

result:

ok single line: '2147483647'