結果
問題 | No.68 よくある棒を切る問題 (2) |
ユーザー | threepipes_s |
提出日時 | 2014-11-17 03:35:52 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,183 ms / 5,000 ms |
コード長 | 1,839 bytes |
コンパイル時間 | 3,536 ms |
コンパイル使用メモリ | 75,204 KB |
実行使用メモリ | 95,308 KB |
最終ジャッジ日時 | 2023-08-30 20:18:37 |
合計ジャッジ時間 | 22,441 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,118 ms
91,504 KB |
testcase_01 | AC | 1,102 ms
93,420 KB |
testcase_02 | AC | 1,081 ms
91,864 KB |
testcase_03 | AC | 1,126 ms
95,296 KB |
testcase_04 | AC | 1,183 ms
91,848 KB |
testcase_05 | AC | 1,146 ms
95,308 KB |
testcase_06 | AC | 1,067 ms
88,288 KB |
testcase_07 | AC | 1,062 ms
89,028 KB |
testcase_08 | AC | 1,071 ms
88,020 KB |
testcase_09 | AC | 1,073 ms
89,720 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Comparator; import java.util.PriorityQueue; public class Main { // public static List<Long> k = new ArrayList<Long>(); public static PriorityQueue<Pair> lens = new PriorityQueue<Pair>(new MyComparator()); // public static HashMap<Long, Integer> cutNum = new HashMap<Long, Integer>(); public static int maxK = (int) 5e5; public static void main(String[] args){ BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); try{ int n = Integer.parseInt(input.readLine().trim()); String tmp0[] = input.readLine().trim().split(" "); int q = Integer.parseInt(input.readLine().trim()); String tmp1[] = input.readLine().trim().split(" "); int[] cutNum = new int[q]; double[] res = new double[maxK]; double[] len = new double[n]; for(int i=0; i<n; i++){ len[i] = Double.parseDouble(tmp0[i]); Pair p = new Pair(len[i], i); lens.add(p); } for(int i=0; i<q; i++){ cutNum[i] = 0; } for(int i=0; i<maxK; i++){ Pair p = lens.poll(); res[i] = p.d; lens.add(new Pair(len[p.i]/(++cutNum[p.i]+1), p.i)); } for(int i=0; i<q; i++){ System.out.println(res[Integer.parseInt(tmp1[i])-1]); } }catch(IOException e){ e.printStackTrace(); } } } class Pair{ double d; int i; public Pair(double d, int i){ this.d = d; this.i = i; } } class MyComparator implements Comparator<Pair> { public int compare(Pair obj1, Pair obj2) { Pair p1 = obj1; Pair p2 = obj2; if(p1.d < p2.d) { return 1; } else if(p1.d > p2.d) { return -1; } else{ return 0; } } }