結果

問題 No.456 Millions of Submits!
ユーザー GrenacheGrenache
提出日時 2016-12-08 01:21:09
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 6,440 bytes
コンパイル時間 5,523 ms
コンパイル使用メモリ 79,112 KB
実行使用メモリ 192,572 KB
最終ジャッジ日時 2023-09-05 10:07:33
合計ジャッジ時間 17,033 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
39,120 KB
testcase_01 AC 44 ms
34,128 KB
testcase_02 AC 45 ms
33,940 KB
testcase_03 AC 44 ms
34,084 KB
testcase_04 AC 44 ms
34,096 KB
testcase_05 AC 66 ms
35,204 KB
testcase_06 AC 65 ms
35,292 KB
testcase_07 AC 163 ms
41,556 KB
testcase_08 AC 164 ms
41,320 KB
testcase_09 AC 440 ms
48,300 KB
testcase_10 AC 452 ms
49,276 KB
testcase_11 AC 1,346 ms
62,640 KB
testcase_12 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.Map.*;


public class Main_yukicoder456 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int m = sc.nextInt();

		int[] a = new int[m];
		int[] b = new int[m];
		double[] t = new double[m];
//		Map<Integer, List<Double>> hm = new HashMap<>();
		Map<Integer, List<Integer>> hm2 = new HashMap<>();
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			t[i] = sc.nextDouble();

			int tmp = a[i] * 100 + b[i];
			if (!hm2.containsKey(tmp)) {
//				hm.put(tmp, new ArrayList<>());
				hm2.put(tmp, new ArrayList<>());
			}
//			hm.get(tmp).add(t[i]);
			hm2.get(tmp).add(i);
		}

		Map<Long, Double> ret = new HashMap<>();
//		Queue<Double> l = new ArrayDeque<>();
//		Queue<Double> r = new ArrayDeque<>();
//		Queue<List<Integer>> ans = new ArrayDeque<>();
//		Queue<Integer> cnt = new ArrayDeque<>();
		Queue<Quad> q = new ArrayDeque<>();
		for (Entry<Integer, List<Integer>> tt : hm2.entrySet()) {
			int aa = tt.getKey() / 100;
			int bb = tt.getKey() % 100;

			q.clear();
			q.add(new Quad(0.0, 30000.0, tt.getValue(), 0));
//			l.add(0.0);
//			r.add(30000.0);
//			ans.add(tt.getValue());
//			cnt.add(0);

			while (!q.isEmpty()) {
				Quad ee = q.remove();
				double ltmp = ee.l;
				double rtmp = ee.r;
				List<Integer> anstmp = ee.ans;
				int cnttmp = ee.cnt;

				if (cnttmp > 50) {
					for (int e : anstmp) {
						ret.put(e * 1_000_000_000L + tt.getKey(), rtmp);
					}
					continue;
				}

				List<Integer> ansr = new ArrayList<>();
				List<Integer> ansl = new ArrayList<>();
//				ansr.clear();
//				ansl.clear();

				double mid = (ltmp + rtmp) / 2;
				double f = Math.pow(mid, aa) * Math.pow(Math.log(mid), bb);

				for (int i = 0, size = anstmp.size(); i < size; i++) {

//					pr.printf("%e %e\n", mid, f);
					if (f >= t[anstmp.get(i)]) {
						ansr.add(anstmp.get(i));
					} else {
						ansl.add(anstmp.get(i));
					}
				}

				if (ansr.size() > 0) {
					q.add(new Quad(ltmp, mid, ansr, cnttmp + 1));
//					l.add(ltmp);
//					r.add(mid);
//					ans.add(ansr);
//					cnt.add(cnttmp + 1);
				}
				if (ansl.size() > 0) {
					q.add(new Quad(mid, rtmp, ansl, cnttmp + 1));
//					l.add(mid);
//					r.add(rtmp);
//					ans.add(ansl);
//					cnt.add(cnttmp + 1);
				}
			}
		}

		for (int i = 0; i < m; i++) {
			long key = i * 1_000_000_000L + a[i] * 100 + b[i];
//			pr.printf("%.10f\n", ret.get(key));
			pr.println(Double.toString(ret.get(key)));
		}
	}

	private static class Quad {
		double l;
		double r;
		List<Integer> ans;
		int cnt;

		Quad(double l, double r, List<Integer> ans, int cnt) {
			this.l = l;
			this.r = r;
			this.ans = ans;
			this.cnt = cnt;
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		private boolean isPrintable(int ch) {
			return ch >= '!' && ch <= '~';
		}

		private boolean isCRLF(int ch) {
			return ch == '\n' || ch == '\r' || ch == -1;
		}

		private int nextPrintable() {
			try {
				int ch;
				while (!isPrintable(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}

				return ch;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		String next() {
			try {
				int ch = nextPrintable();
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (isPrintable(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		int nextInt() {
			try {
				// parseInt from Integer.parseInt()
				boolean negative = false;
				int res = 0;
				int limit = -Integer.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Integer.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				int multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		long nextLong() {
			try {
				// parseLong from Long.parseLong()
				boolean negative = false;
				long res = 0;
				long limit = -Long.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Long.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				long multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

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

		String nextLine() {
			try {
				int ch;
				while (isCRLF(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (!isCRLF(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new NoSuchElementException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0