結果
問題 | No.2099 [Cherry Alpha B] Time Machine |
ユーザー |
![]() |
提出日時 | 2022-10-14 21:41:24 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,350 bytes |
コンパイル時間 | 2,720 ms |
コンパイル使用メモリ | 78,316 KB |
実行使用メモリ | 507,532 KB |
最終ジャッジ日時 | 2024-06-26 13:29:51 |
合計ジャッジ時間 | 8,991 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 66 |
ソースコード
import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int x = sc.nextInt(); int a = sc.nextInt(); int y = sc.nextInt(); int b = sc.nextInt(); sc.close(); int m = 20000001; int m2 = 10000000 - t; t += m2; long[] d = new long[m]; Arrays.fill(d, Long.MAX_VALUE); d[m2] = 0; PriorityQueue<Node> que = new PriorityQueue<Node>(); Node first = new Node(m2, 0); que.add(first); int[] dx = {1, a, -b}; int[] dd = {1, x, y}; while (!que.isEmpty()) { Node cur = que.poll(); if (cur.d > d[cur.v]) { continue; } if (cur.v == t) { System.out.println(d[cur.v]); return; } for (int i = 0; i < 3; i++) { int next = cur.v + dx[i]; if (next < 0 || m <= next) { continue; } long alt = d[cur.v] + dd[i]; if (alt < d[next]) { d[next] = alt; que.add(new Node(next, alt)); } } } } static class Hen { int v, c; public Hen(int v, int c) { this.v = v; this.c = c; } } static class Node implements Comparable<Node> { int v; long d; public Node(int v, long d) { this.v = v; this.d = d; } public int compareTo(Node o) { return Long.compare(d, o.d); } } }