結果

問題 No.5017 Tool-assisted Shooting
ユーザー ks2mks2m
提出日時 2023-07-16 16:47:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 6,349 bytes
コンパイル時間 3,097 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 74,920 KB
スコア 4,035,021
平均クエリ数 985.23
最終ジャッジ日時 2023-07-16 16:48:34
合計ジャッジ時間 42,665 ms
ジャッジサーバーID
(参考情報)
judge12 / judge17
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 360 ms
73,248 KB
testcase_01 AC 321 ms
71,820 KB
testcase_02 AC 316 ms
73,464 KB
testcase_03 AC 466 ms
74,700 KB
testcase_04 AC 316 ms
73,088 KB
testcase_05 AC 308 ms
73,248 KB
testcase_06 AC 326 ms
72,776 KB
testcase_07 AC 313 ms
72,324 KB
testcase_08 AC 319 ms
72,400 KB
testcase_09 AC 329 ms
73,580 KB
testcase_10 AC 312 ms
72,568 KB
testcase_11 AC 306 ms
73,156 KB
testcase_12 AC 133 ms
69,552 KB
testcase_13 AC 315 ms
72,492 KB
testcase_14 AC 316 ms
73,132 KB
testcase_15 AC 299 ms
72,792 KB
testcase_16 AC 315 ms
73,108 KB
testcase_17 AC 325 ms
72,780 KB
testcase_18 AC 312 ms
72,464 KB
testcase_19 AC 325 ms
72,888 KB
testcase_20 AC 346 ms
73,672 KB
testcase_21 AC 322 ms
72,760 KB
testcase_22 AC 321 ms
72,428 KB
testcase_23 AC 313 ms
71,772 KB
testcase_24 AC 325 ms
73,052 KB
testcase_25 AC 322 ms
73,024 KB
testcase_26 AC 311 ms
73,788 KB
testcase_27 AC 315 ms
73,328 KB
testcase_28 AC 317 ms
72,508 KB
testcase_29 AC 304 ms
72,896 KB
testcase_30 AC 326 ms
73,016 KB
testcase_31 AC 322 ms
72,532 KB
testcase_32 AC 306 ms
72,632 KB
testcase_33 AC 314 ms
72,428 KB
testcase_34 AC 315 ms
73,120 KB
testcase_35 AC 308 ms
73,388 KB
testcase_36 AC 308 ms
73,196 KB
testcase_37 AC 344 ms
70,960 KB
testcase_38 AC 319 ms
73,144 KB
testcase_39 AC 322 ms
73,448 KB
testcase_40 AC 337 ms
72,764 KB
testcase_41 AC 317 ms
72,524 KB
testcase_42 AC 317 ms
73,652 KB
testcase_43 AC 458 ms
73,564 KB
testcase_44 AC 306 ms
73,976 KB
testcase_45 AC 313 ms
72,364 KB
testcase_46 AC 334 ms
73,320 KB
testcase_47 AC 318 ms
72,820 KB
testcase_48 AC 315 ms
72,912 KB
testcase_49 AC 306 ms
73,864 KB
testcase_50 AC 315 ms
72,328 KB
testcase_51 AC 318 ms
72,572 KB
testcase_52 AC 314 ms
71,960 KB
testcase_53 AC 357 ms
71,380 KB
testcase_54 AC 319 ms
73,248 KB
testcase_55 AC 429 ms
74,560 KB
testcase_56 AC 451 ms
74,232 KB
testcase_57 AC 215 ms
72,760 KB
testcase_58 AC 316 ms
73,368 KB
testcase_59 AC 359 ms
73,480 KB
testcase_60 AC 311 ms
73,288 KB
testcase_61 AC 309 ms
72,272 KB
testcase_62 AC 323 ms
73,372 KB
testcase_63 AC 347 ms
72,956 KB
testcase_64 AC 325 ms
73,228 KB
testcase_65 AC 315 ms
74,056 KB
testcase_66 AC 340 ms
73,160 KB
testcase_67 AC 307 ms
72,384 KB
testcase_68 AC 315 ms
71,680 KB
testcase_69 AC 353 ms
73,492 KB
testcase_70 AC 324 ms
73,168 KB
testcase_71 AC 320 ms
72,520 KB
testcase_72 AC 337 ms
73,632 KB
testcase_73 AC 319 ms
71,960 KB
testcase_74 AC 320 ms
73,468 KB
testcase_75 AC 325 ms
73,688 KB
testcase_76 AC 335 ms
74,568 KB
testcase_77 AC 313 ms
73,528 KB
testcase_78 AC 308 ms
71,752 KB
testcase_79 AC 343 ms
70,660 KB
testcase_80 AC 313 ms
73,484 KB
testcase_81 AC 320 ms
72,680 KB
testcase_82 AC 341 ms
74,920 KB
testcase_83 AC 314 ms
71,920 KB
testcase_84 AC 317 ms
74,540 KB
testcase_85 AC 311 ms
72,512 KB
testcase_86 AC 314 ms
73,132 KB
testcase_87 AC 318 ms
71,172 KB
testcase_88 AC 314 ms
72,572 KB
testcase_89 AC 352 ms
72,900 KB
testcase_90 AC 325 ms
72,984 KB
testcase_91 AC 316 ms
72,500 KB
testcase_92 AC 321 ms
74,476 KB
testcase_93 AC 316 ms
72,784 KB
testcase_94 AC 306 ms
73,008 KB
testcase_95 AC 323 ms
71,424 KB
testcase_96 AC 350 ms
70,352 KB
testcase_97 AC 308 ms
72,452 KB
testcase_98 AC 320 ms
73,696 KB
testcase_99 AC 342 ms
73,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	static int H = 60;
	static int H1;
	static int W = 25;
	static int T = 1000;
	static int[][] hp0, hp, pw;
	static int[] ap, ap5;
	static int score, cx, lv, sum, t;
	static List<Character> ok;

	public static void main(String[] args) throws Exception {
		if (batch) {
			readFile = true;
		}
		if (readFile) {
			if (batch) {
				long tl = 2000; // TODO
				long tw = tl - 200;
				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 < 10; z++) {
					try {
						long st = System.currentTimeMillis();
						int score = solve(z);
						long time = System.currentTimeMillis() - st;
						if (time > tw) {
							System.out.println(score + "\t" + time + "ms");
							if (time > tl) {
								tle++;
							}
						} else {
							System.out.println(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(br);
		}
	}

	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:\\yuki\\006\\in\\" + sb.toString() + ".txt");
		BufferedReader br = new BufferedReader(new FileReader(file));
		br.readLine();
		init(br);

		return solve(br);
	}

	static void init(BufferedReader br) throws Exception {
		H1 = H - 1;
		hp0 = new int[W][H];
		hp = new int[W][H];
		pw = new int[W][H];
		ap = new int[W];
		ap5 = new int[W];
		score = 0;
		cx = 12;
		lv = 1;
		sum = 0;
		ok = new ArrayList<>(3);
	}

	static int solve(BufferedReader br) throws Exception {
		for (t = 0; t < T; t++) {
			int n = Integer.parseInt(br.readLine());
			if (n == -1) {
				return score;
			}

			// 1マス下がる
			for (int y = 0; y < H1; y++) {
				for (int x = 0; x < W; x++) {
					hp0[x][y] = hp0[x][y + 1];
					hp[x][y] = hp[x][y + 1];
					pw[x][y] = pw[x][y + 1];
				}
			}
			for (int x = 0; x < W; x++) {
				hp0[x][H1] = 0;
				hp[x][H1] = 0;
				pw[x][H1] = 0;
			}

			// 敵機出現
			for (int i = 0; i < n; i++) {
				String[] sa = br.readLine().split(" ");
				int h = Integer.parseInt(sa[0]);
				int p = Integer.parseInt(sa[1]);
				int x = Integer.parseInt(sa[2]);
				hp0[x][H1] = h;
				hp[x][H1] = h;
				pw[x][H1] = p;
				ap[x]++;
			}
			for (int x = 0; x < W; x++) {
				int val = 0;
				for (int x2 = x - 2; x2 <= x + 2; x2++) {
					int x3 = x2;
					if (x3 < 0) x3 += W;
					if (x3 >= W) x3 -= W;
					val += ap[x3];
				}
				ap5[x] = val;
			}

			// 自機移動
			char dir = getMoveDir();
			if (dir == 'L') {
				cx = left(cx);
			} else if (dir == 'R') {
				cx = right(cx);
			}
			if (!readFile) {
				System.out.println(dir);
			}

			// 攻撃
			for (int y = 1; y < H; y++) {
				if (hp[cx][y] > 0) {
					hp[cx][y] -= lv;
					if (hp[cx][y] <= 0) {
						hp[cx][y] = 0;
						score += hp0[cx][y];
						sum += pw[cx][y];
						lv = 1 + sum / 100;
					}
					break;
				}
			}
		}
		return score;
	}

	static char getMoveDir() {
		ok.clear();
		int lx = left(cx);
		int rx = right(cx);
		if (hp[lx][0] == 0 && hp[lx][1] <= lv) {
			ok.add('L');
		}
		if (hp[rx][0] == 0 && hp[rx][1] <= lv) {
			ok.add('R');
		}
		if (hp[cx][1] <= lv) {
			ok.add('S');
		}
		if (ok.isEmpty()) {
			return 'S';
		}
		if (ok.size() == 1) {
			return ok.get(0);
		}

		Teki[] arr = new Teki[W];
		int cnt = 0;
		for (int x = 0; x < W; x++) {
			for (int y = 1; y < H; y++) {
				if (hp[x][y] > 0) {
					arr[x] = makeTarget(x, y);
					if (arr[x] != null) {
						cnt++;
					}
					break;
				}
			}
		}

		if (cnt == 0) {
			int max = 0;
			int maxidx = 0;
			for (int x = 0; x < W; x++) {
				if (ap5[x] > max) {
					max = ap5[x];
					maxidx = x;
				}
			}
			if (maxidx == cx && ok.contains('S')) {
				return 'S';
			}
			char ret = near(cx, maxidx);
			if (ok.contains(ret)) {
				return ret;
			}
			return 'S';

		} else {
			Teki best = null;
			for (int x = 0; x < W; x++) {
				Teki o = arr[x];
				if (o != null) {
					// TODO
					if (t < 700) {
						o.val = (double) o.pw / o.turn;
					} else {
						o.val = (double) o.hp0 / o.turn;
					}
					if (best == null || o.val > best.val) {
						best = o;
					}
				}
			}
			return best.dir;
		}
	}

	static Teki makeTarget(int x, int y) {
		int dx = W;
		char dir = 'S';
		if (x == cx) {
			dx = 0;
		} else {
			if (ok.contains('L')) {
				if (x <= cx) {
					dx = cx - x - 1;
				} else {
					dx = cx + W - x - 1;
				}
				dir = 'L';
			}
			if (ok.contains('R')) {
				int dx2 = 0;
				if (cx <= x) {
					dx2 = x - cx - 1;
				} else {
					dx2 = x + W - cx - 1;
				}
				if (dx2 < dx) {
					dx = dx2;
					dir = 'R';
				}
			}
		}
		int dy = y - dx;
		int cnt = (hp[x][y] + lv - 1) / lv;
		if (dy < cnt) {
			return null;
		}
		Teki ret = new Teki(x, y);
		ret.dir = dir;
		ret.turn = dx + cnt;
		return ret;
	}

	static char near(int from, int to) {
		int dxl = from - to;
		if (dxl < 0) dxl += W;
		int dxr = to - from;
		if (dxr < 0) dxr += W;
		if (dxl <= dxr) {
			return 'L';
		} else {
			return 'R';
		}
	}

	static int left(int x) {
		x--;
		if (x == -1) {
			x = W - 1;
		}
		return x;
	}

	static int right(int x) {
		x++;
		if (x == W) {
			x = 0;
		}
		return x;
	}

	static class Teki {
		int x, y, hp0, hp, pw;
		int turn;
		char dir;
		double val;

		public Teki(int x, int y) {
			this.x = x;
			this.y = y;
			this.hp0 = Main.hp0[x][y];
			this.hp = Main.hp[x][y];
			this.pw = Main.pw[x][y];
		}
	}
}
0