結果

問題 No.210 探し物はどこですか?
ユーザー tenten
提出日時 2021-01-20 13:15:08
言語 Java
(openjdk 23)
結果
AC  
実行時間 758 ms / 2,000 ms
コード長 1,396 bytes
コンパイル時間 4,733 ms
コンパイル使用メモリ 77,928 KB
実行使用メモリ 45,108 KB
最終ジャッジ日時 2024-12-23 00:54:47
合計ジャッジ時間 25,050 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		PriorityQueue<Room> queue = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    queue.add(new Room(arr[i], sc.nextInt()));
		}
		double ans = 0;
		for (int i = 1; i < 1000000; i++) {
		    Room r = queue.poll();
		    ans += r.getRate() * i;
		    queue.add(r);
		}
		System.out.println(ans);
	}
	
	static class Room implements Comparable<Room> {
	    double baseRate;
	    double findRate;
	    
	    public Room(double baseRate, double findRate) {
	        this.baseRate = baseRate;
	        this.findRate = findRate;
	    }
	    
	    public Room(int r1, int r2) {
	        this(r1 / 1000.0, r2 / 100.0);
	    }
	    
	    public int compareTo(Room another) {
	        double d1 = getPrivateRate();
	        double d2 = another.getPrivateRate();
	        if (d1 == d2) {
	            return 0;
	        } else if (d1 > d2) {
	            return -1;
	        } else {
	            return 1;
	        }
	    }
	    
	    private double getPrivateRate() {
	        return baseRate * findRate;
	    }
	    
	    public double getRate() {
	        double ans = getPrivateRate();
	        baseRate *= (1 - findRate);
	        return ans;
	    }
	}
}
0