結果

問題 No.33 アメーバがたくさん
ユーザー fujisufujisu
提出日時 2015-03-06 05:18:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,379 bytes
コンパイル時間 2,510 ms
コンパイル使用メモリ 88,344 KB
実行使用メモリ 53,828 KB
最終ジャッジ日時 2023-10-24 17:45:20
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,800 KB
testcase_01 AC 51 ms
53,800 KB
testcase_02 AC 52 ms
52,716 KB
testcase_03 AC 52 ms
53,808 KB
testcase_04 WA -
testcase_05 AC 52 ms
52,712 KB
testcase_06 AC 52 ms
53,804 KB
testcase_07 AC 52 ms
53,800 KB
testcase_08 WA -
testcase_09 AC 54 ms
52,732 KB
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	void add(int key, int value, TreeMap<Integer, Integer> map) {
		if (map.get(key) == null) {
			map.put(key, value);
		} else {
			map.put(key, map.get(key) + value);
		}
	}

	void run() {
		MyScanner sc = new MyScanner();

		int n = sc.nextInt();
		int d = sc.nextInt();
		int t = sc.nextInt();
		int[] a = sc.nextIntArray(n);

		TreeMap<Integer, TreeSet<Integer>> map = new TreeMap<Integer, TreeSet<Integer>>();
		for (int i = 0; i < n; i++) {
			int rem = a[i] % d;
			if (map.get(rem) == null) {
				TreeSet<Integer> l = new TreeSet<Integer>();
				l.add(a[i]);
				map.put(rem, l);
			} else {
				map.get(rem).add(a[i]);
			}
		}

		BigInteger sum = new BigInteger("0");
		for (Integer key : map.keySet()) {
			TreeSet<Integer> set = map.get(key);

			TreeMap<Integer, Integer> array = new TreeMap<Integer, Integer>();
			for (Integer pos : set) {
				int l = pos - t * d;
				int r = pos + t * d;
				add(l, 1, array);
				add(r + d, -1, array);
			}

			int ameba = 0;
			int pre = -1;
			for (Integer pos : array.keySet()) {
				if (0 < ameba) {
					String tmp = "" + ((pos - pre) / d);
					sum = sum.add(new BigInteger(tmp));
				}

				int value = array.get(pos);
				ameba += value;
				pre = pos;
			}
		}

		System.out.println(sum);
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}
		System.out.println("----------------------------" + '\n');
	}

	class MyScanner {
		int read() {
			try {
				return System.in.read();
			} catch (IOException e) {
				throw new InputMismatchException();
			}
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

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

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}
0