結果
問題 | No.2766 Delicious Multiply Spice |
ユーザー |
![]() |
提出日時 | 2024-05-31 22:06:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 162 ms / 2,000 ms |
コード長 | 668 bytes |
コンパイル時間 | 3,194 ms |
コンパイル使用メモリ | 90,372 KB |
実行使用メモリ | 54,236 KB |
最終ジャッジ日時 | 2024-12-20 23:36:56 |
合計ジャッジ時間 | 11,212 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 8 |
other | AC * 31 |
ソースコード
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); sc.close(); System.out.println(dfs(n)); } static Map<Long, String> map = new HashMap<>(); static String dfs(long n) { if (map.containsKey(n)) { return map.get(n); } if (n == 1) { return ""; } n--; String res = ""; if (n % 2 == 0) { res = dfs(n / 2); if (res != null) { return res + "A"; } } if (n % 3 == 0) { res = dfs(n / 3); if (res != null) { return res + "B"; } } return null; } }