結果

問題 No.683 Two Operations No.3
ユーザー tentententen
提出日時 2022-08-10 18:57:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,656 bytes
コンパイル時間 3,564 ms
コンパイル使用メモリ 78,760 KB
実行使用メモリ 53,468 KB
最終ジャッジ日時 2023-10-21 04:23:38
合計ジャッジ時間 5,863 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
52,916 KB
testcase_01 AC 56 ms
53,448 KB
testcase_02 AC 56 ms
52,368 KB
testcase_03 AC 56 ms
53,448 KB
testcase_04 AC 57 ms
53,464 KB
testcase_05 AC 55 ms
52,396 KB
testcase_06 AC 54 ms
52,384 KB
testcase_07 AC 57 ms
53,468 KB
testcase_08 AC 56 ms
53,448 KB
testcase_09 AC 56 ms
53,460 KB
testcase_10 AC 56 ms
53,452 KB
testcase_11 AC 56 ms
53,448 KB
testcase_12 AC 55 ms
52,340 KB
testcase_13 AC 56 ms
53,456 KB
testcase_14 AC 56 ms
52,728 KB
testcase_15 AC 57 ms
52,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static HashMap<Long, HashSet<Long>> dp = new HashMap<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        if (dfw(sc.nextLong(), sc.nextLong())) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    
    static boolean dfw(long a, long b) {
        if (!dp.containsKey(a)) {
            dp.put(a, new HashSet<>());
        }
        if (!dp.get(a).contains(b)) {
            if (a == 0 || b == 0) {
                return true;
            }
            if (a % 2 == 0) {
                if (dfw(a / 2, b - 1)) {
                    return true;
                }
            }
            if (b % 2 == 0) {
                if (dfw(a - 1, b / 2)) {
                    return true;
                }
            }
            dp.get(a).add(b);
        }
        return false;
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0