結果

問題 No.68 よくある棒を切る問題 (2)
ユーザー リチウムリチウム
提出日時 2014-11-17 03:53:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 630 ms / 5,000 ms
コード長 1,971 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 83,196 KB
実行使用メモリ 75,800 KB
最終ジャッジ日時 2023-08-30 20:21:04
合計ジャッジ時間 15,812 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 586 ms
65,632 KB
testcase_01 AC 591 ms
65,508 KB
testcase_02 AC 591 ms
65,516 KB
testcase_03 AC 615 ms
75,652 KB
testcase_04 AC 630 ms
75,800 KB
testcase_05 AC 618 ms
75,736 KB
testcase_06 AC 580 ms
65,480 KB
testcase_07 AC 589 ms
65,716 KB
testcase_08 AC 587 ms
71,392 KB
testcase_09 AC 600 ms
72,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		MyScanner sc=new MyScanner();
		int n=sc.nextInt();
		int L[]=new int[n];
		for(int i=0;i<n;i++){
			L[i]=sc.nextInt();
		}
		int m=sc.nextInt();
		int k[]=new int[m];
		for(int i=0;i<m;i++){
			k[i]=sc.nextInt();
		}
		int get[]=new int[n];
		double ans[]=new double[500001];
		PriorityQueue <connect>Q=new PriorityQueue<>();
		for(int i=0;i<n;i++){
			Q.add(new connect(L[i],i));
		}
		for(int i=1;i<500001;i++){
			connect con=Q.poll();
			ans[i]=con.a;
			get[con.b]++;
			Q.add(new connect((double)L[con.b]/(get[con.b]+1),con.b));
		}
		StringBuilder s=new StringBuilder("");
		for(int i=0;i<m;i++){
		String S=""+ans[k[i]];	
		s.append(S+"\n");
		}
		System.out.print(s);
		
	}
}

class MyScanner {
	int nextInt() {
		try {
			int c = System.in.read();
			while (c != '-' && (c < '0' || '9' < c))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = System.in.read();
			} while ('0' <= c && c <= '9');
			return res;
		} catch (Exception e) {
			return -1;
		}
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	String next() {
		try {
			StringBuilder res = new StringBuilder("");
			int c = System.in.read();
			while (Character.isWhitespace(c))
				c = System.in.read();
			do {
				res.append((char) c);
			} while (!Character.isWhitespace(c = System.in.read()));
			return res.toString();
		} catch (Exception e) {
			return null;
		}
	}
}

class connect implements Comparable<connect> {
	double a;
	int b;

	public connect(double a,int b) {
		this.a = a;
		this.b = b;
	}

	public connect() {
	}

	@Override
	public int compareTo(connect o) {
		if(this.a>o.a)return -1;
		if(this.a==o.a)return 0;
		return 1;
	}

}
0