結果
問題 |
No.854 公平なりんご分配
|
ユーザー |
![]() |
提出日時 | 2020-01-28 09:06:52 |
言語 | Java (openjdk 23) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,628 bytes |
コンパイル時間 | 2,369 ms |
コンパイル使用メモリ | 79,632 KB |
実行使用メモリ | 584,504 KB |
最終ジャッジ日時 | 2024-09-15 05:45:32 |
合計ジャッジ時間 | 82,685 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 WA * 19 TLE * 15 MLE * 11 -- * 11 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<Integer, Integer>[] maps = new HashMap[n + 1]; maps[0] = new HashMap<>(); for (int i = 1; i <= n; i++) { maps[i] =(HashMap<Integer, Integer>)(maps[i - 1].clone()); int x = sc.nextInt(); for (int j = 2; j <= Math.sqrt(x); j++) { while (x % j == 0) { if (maps[i].containsKey(j)) { maps[i].put(j, maps[i].get(j) + 1); } else { maps[i].put(j, 1); } x /= j; } } if (x > 1) { if (maps[i].containsKey(x)) { maps[i].put(x, maps[i].get(x) + 1); } else { maps[i].put(x, 1); } } } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int p = sc.nextInt(); int left = sc.nextInt(); int right = sc.nextInt(); HashMap<Integer, Integer> target = (HashMap<Integer, Integer>)(maps[right].clone()); for (Map.Entry<Integer, Integer> entry : maps[left - 1].entrySet()) { target.put(entry.getKey(), target.get(entry.getKey()) - entry.getValue()); } boolean flag = true; for (int j = 2; j <= Math.sqrt(p) && flag; j++) { while (p % j == 0 && flag) { if (target.containsKey(j)) { int x = target.get(j); x--; if (x < 0) { flag = false; } else { target.put(j, x); } } else { flag = false; } p /= j; } } if (flag && p > 1) { if (target.containsKey(p)) { int x = target.get(p); x--; if (x < 0) { flag = false; } } else { flag = false; } } if (flag) { sb.append("Yes"); } else { sb.append("NO"); } sb.append("\n"); } System.out.print(sb); } }