結果

問題 No.104 国道
ユーザー YamaKasa
提出日時 2018-04-24 04:05:21
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 593 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 74,784 KB
実行使用メモリ 41,452 KB
最終ジャッジ日時 2024-06-27 15:48:49
合計ジャッジ時間 5,377 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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