結果

問題 No.104 国道
ユーザー YamaKasaYamaKasa
提出日時 2018-04-24 04:05:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 593 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 72,388 KB
実行使用メモリ 56,488 KB
最終ジャッジ日時 2023-09-09 23:23:03
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,040 KB
testcase_01 AC 118 ms
55,968 KB
testcase_02 AC 121 ms
55,872 KB
testcase_03 AC 120 ms
55,592 KB
testcase_04 AC 119 ms
56,296 KB
testcase_05 AC 117 ms
55,912 KB
testcase_06 AC 119 ms
55,972 KB
testcase_07 AC 121 ms
55,932 KB
testcase_08 AC 119 ms
56,064 KB
testcase_09 AC 122 ms
55,540 KB
testcase_10 AC 120 ms
56,056 KB
testcase_11 AC 120 ms
56,488 KB
testcase_12 AC 118 ms
55,752 KB
testcase_13 AC 116 ms
56,052 KB
testcase_14 AC 120 ms
56,052 KB
testcase_15 AC 119 ms
55,632 KB
testcase_16 AC 119 ms
55,960 KB
testcase_17 AC 118 ms
56,068 KB
testcase_18 AC 121 ms
55,856 KB
testcase_19 AC 125 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		scan.close();
		if(s.length() == 0) {
			System.out.println("1");
			System.exit(0);
		}

		int l = s.length();
		int h = (int)Math.pow(2, l);
		int k = 0;

		for(int i = 0; i < l; i++) {
			if(s.substring(i, i + 1).equals("R")) {
				if(k == 0) {
					k = 1;
				}else {
					k = 2 * k + 1;
				}
			}else {
				if(k == 0) {
					k = 0;
				}else {
					k = 2 * k;
				}
			}
		}
		int ans = k + h;
		System.out.println(ans);
	}
}
0