結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー 37zigen37zigen
提出日時 2017-04-29 07:09:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,599 ms / 4,000 ms
コード長 2,409 bytes
コンパイル時間 3,018 ms
コンパイル使用メモリ 75,504 KB
実行使用メモリ 93,440 KB
最終ジャッジ日時 2023-08-16 03:08:21
合計ジャッジ時間 19,772 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,696 KB
testcase_01 AC 112 ms
55,588 KB
testcase_02 AC 112 ms
55,608 KB
testcase_03 AC 112 ms
55,980 KB
testcase_04 AC 111 ms
56,320 KB
testcase_05 AC 118 ms
55,572 KB
testcase_06 AC 115 ms
55,768 KB
testcase_07 AC 113 ms
55,724 KB
testcase_08 AC 114 ms
56,124 KB
testcase_09 AC 119 ms
55,912 KB
testcase_10 AC 116 ms
58,024 KB
testcase_11 AC 115 ms
55,740 KB
testcase_12 AC 120 ms
55,612 KB
testcase_13 AC 120 ms
55,424 KB
testcase_14 AC 115 ms
55,584 KB
testcase_15 AC 123 ms
56,084 KB
testcase_16 AC 117 ms
55,924 KB
testcase_17 AC 116 ms
55,424 KB
testcase_18 AC 122 ms
57,648 KB
testcase_19 AC 112 ms
55,980 KB
testcase_20 AC 116 ms
55,832 KB
testcase_21 AC 198 ms
59,928 KB
testcase_22 AC 189 ms
59,572 KB
testcase_23 AC 188 ms
59,528 KB
testcase_24 AC 171 ms
58,156 KB
testcase_25 AC 203 ms
59,176 KB
testcase_26 AC 194 ms
59,332 KB
testcase_27 AC 197 ms
59,400 KB
testcase_28 AC 206 ms
59,472 KB
testcase_29 AC 1,599 ms
93,288 KB
testcase_30 AC 1,446 ms
92,256 KB
testcase_31 AC 1,349 ms
91,968 KB
testcase_32 AC 1,132 ms
86,044 KB
testcase_33 AC 1,186 ms
72,184 KB
testcase_34 AC 1,066 ms
68,708 KB
testcase_35 AC 1,577 ms
93,440 KB
testcase_36 AC 1,541 ms
93,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int w = sc.nextInt();
		long h = sc.nextLong();
		int[] a = new int[n];
		long[] b = new long[n];
		int[] x = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextLong();
			x[i] = sc.nextInt();
			--x[i];
		}
		RMS rms = new RMS(w);
		int[] ps = new int[2];
		for (int i = 0; i < n; ++i) {
			rms.update(x[i], x[i] + a[i], b[i]);
			while (rms.query(x[i], x[i] + a[i])[0] >= h) {
				int idx = (int) rms.query(x[i], x[i] + a[i])[1];
				rms.update(idx, idx + 1, -rms.INF);
				++ps[i % 2];
			}
		}
		if (ps[0] > ps[1]) {
			System.out.println("A");
		} else if (ps[0] < ps[1]) {
			System.out.println("B");
		} else {
			System.out.println("DRAW");
		}

	}

	class RMS {
		int n;
		long[][] v;
		final long INF = Long.MAX_VALUE / 16;
		long[] lazy;

		public RMS(int n) {
			this.n = 1;
			while (this.n < n) {
				this.n *= 2;
			}
			n = this.n;
			v = new long[2 * n - 1][2];
			lazy = new long[2 * n - 1];
			for (int i = 0; i < n; ++i) {
				v[i + n - 1][1] = i;
			}
			for (int i = n - 2; i >= 0; --i) {
				v[i] = merge(v[2 * i + 1], v[2 * i + 2]);
			}
		}

		void push(int k) {
			v[k][0] += lazy[k];
			if (k < n - 1) {
				lazy[2 * k + 1] += lazy[k];
				lazy[2 * k + 2] += lazy[k];
			}
			lazy[k] = 0;
		}

		long[] merge(long[] o1, long[] o2) {
			if (o1[0] > o2[0]) {
				return new long[] { o1[0], o1[1] };
			} else {
				return new long[] { o2[0], o2[1] };
			}
		}

		long[] update(int a, int b, long add) {
			return query(a, b, 0, n, 0, add);
		}

		long[] query(int a, int b) {
			return update(a, b, 0);
		}

		long[] query(int a, int b, int l, int r, int k, long add) {
			push(k);
			if (b <= l || a >= r) {
				return new long[] { -INF, -1 };
			} else if (a <= l && r <= b) {
				lazy[k] += add;
				push(k);
				return v[k];
			} else {
				long[] vl = query(a, b, l, (l + r) / 2, 2 * k + 1, add);
				long[] vr = query(a, b, (l + r) / 2, r, 2 * k + 2, add);
				v[k] = merge(v[2 * k + 1], v[2 * k + 2]);
				return merge(vl, vr);
			}
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0