結果

問題 No.5007 Steiner Space Travel
ユーザー ks2mks2m
提出日時 2022-07-30 14:49:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 88 ms / 1,000 ms
コード長 3,840 bytes
コンパイル時間 2,180 ms
実行使用メモリ 37,408 KB
スコア 4,521,707
最終ジャッジ日時 2022-07-30 14:49:53
合計ジャッジ時間 6,528 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
35,700 KB
testcase_01 AC 79 ms
35,652 KB
testcase_02 AC 83 ms
37,144 KB
testcase_03 AC 88 ms
37,196 KB
testcase_04 AC 86 ms
35,796 KB
testcase_05 AC 81 ms
35,744 KB
testcase_06 AC 81 ms
35,956 KB
testcase_07 AC 78 ms
35,516 KB
testcase_08 AC 81 ms
35,528 KB
testcase_09 AC 83 ms
35,572 KB
testcase_10 AC 84 ms
35,756 KB
testcase_11 AC 82 ms
35,716 KB
testcase_12 AC 81 ms
35,672 KB
testcase_13 AC 79 ms
35,552 KB
testcase_14 AC 79 ms
35,656 KB
testcase_15 AC 81 ms
35,712 KB
testcase_16 AC 82 ms
35,680 KB
testcase_17 AC 78 ms
35,600 KB
testcase_18 AC 78 ms
35,708 KB
testcase_19 AC 85 ms
35,596 KB
testcase_20 AC 78 ms
35,736 KB
testcase_21 AC 87 ms
37,344 KB
testcase_22 AC 81 ms
35,528 KB
testcase_23 AC 81 ms
35,612 KB
testcase_24 AC 80 ms
35,664 KB
testcase_25 AC 81 ms
35,520 KB
testcase_26 AC 78 ms
35,564 KB
testcase_27 AC 78 ms
35,628 KB
testcase_28 AC 79 ms
35,580 KB
testcase_29 AC 84 ms
37,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	static boolean batch = false;
	static boolean readFile = false;
	static int num = 0;

	static int a = 5;
	static int N, M;
	static Obj[] pln;

	public static void main(String[] args) throws Exception {
		if (batch) {
			readFile = true;
		}
		if (readFile) {
			if (batch) {
				long tl = 1000;
				long tw = (long) (tl * 0.9);
				long total = 0;
				int bidx = 0;
				int best = 0;
				int widx = 0;
				int worst = 1000000000;
				int re = 0;
				int tle = 0;
				for (int z = 0; z < 100; z++) {
					try {
						long st = System.currentTimeMillis();
						int score = solve(z);
						long time = System.currentTimeMillis() - st;
						if (time > tw) {
							System.out.println(z + ":\t" + score + "\t" + time + "ms");
							if (time > tl) {
								tle++;
							}
						} else {
							System.out.println(z + ":\t" + score);
						}
						total += score;
						if (score > best) {
							best = score;
							bidx = z;
						}
						if (score < worst) {
							worst = score;
							widx = z;
						}
					} catch (Exception e) {
						System.out.println(z + ":\t" + e.getMessage());
						re++;
					}
				}
				System.out.println("total: " + total);
				System.out.println("best: " + bidx + ": " + best);
				System.out.println("worst: " + widx + ": " + worst);
				System.out.println("RE: " + re);
				System.out.println("TLE: " + tle);
			} else {
				int score = solve(num);
				System.out.println(score);
			}

		} else {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			init(br);
			solve();
		}
	}

	static int solve(int z) throws Exception {
		StringBuilder sb = new StringBuilder();
		sb.append(z);
		while (sb.length() < 4) {
			sb.insert(0, '0');
		}
		File file = new File("G:\\input\\" + sb.toString() + ".txt");
		BufferedReader br = new BufferedReader(new FileReader(file));
		init(br);

		return solve();
	}

	static void init(BufferedReader br) throws Exception {
		String[] sa = br.readLine().split(" ");
		N = Integer.parseInt(sa[0]);
		M = Integer.parseInt(sa[1]);
		pln = new Obj[N];
		for (int i = 0; i < N; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.t = 1;
			o.i = i;
			o.x = Integer.parseInt(sa[0]);
			o.y = Integer.parseInt(sa[1]);
			pln[i] = o;
		}
	}

	static int solve() throws Exception {
		Obj[] sta = new Obj[M];
		for (int i = 0; i < M; i++) {
			Obj o = new Obj();
			o.t = 2;
			o.i = i;
			sta[i] = o;
		}

		Set<Obj> rem = new HashSet<>();
		for (int i = 1; i < N; i++) {
			rem.add(pln[i]);
		}

		List<Obj> ans = new ArrayList<>();
		ans.add(pln[0]);
		Obj now = pln[0];
		while (!rem.isEmpty()) {
			int min = Integer.MAX_VALUE;
			Obj next = null;
			for (Obj o : rem) {
				if (next == null) {
					min = dist(now, o);
					next = o;
					continue;
				}
				int d = dist(now, o);
				if (d < min) {
					min = d;
					next = o;
				}
			}
			ans.add(next);
			rem.remove(next);
			now = next;
		}
		ans.add(pln[0]);

		PrintWriter pw = new PrintWriter(System.out);
		int v = ans.size();
		for (Obj o : sta) {
			pw.println(o.x + " " + o.y);
		}
		pw.println(v);
		pw.println("1 1");
		int s = 0;
		for (int i = 1; i < v; i++) {
			Obj o = ans.get(i);
			pw.println(o.t + " " +  (o.i + 1));
			Obj o1 = ans.get(i - 1);
			int e = dist(o1, o);
			if (o1.t == 1) e *= a;
			if (o.t == 1) e *= a;
			s += e;
		}
		pw.flush();
		int score = (int) Math.round(1000000000 / (1000 + Math.sqrt(s)));
		return score;
	}

	static int dist(Obj o1, Obj o2) {
		int dx = o1.x - o2.x;
		int dy = o1.y - o2.y;
		return dx * dx + dy * dy;
	}

	static class Obj {
		int t, i, x, y;
	}
}
0