0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ABC - 134- A&B&C&D&E

Posted at

#AtCoder ABC 134 A&B&C&D&E
AtCoder - 134

E/Fは時間切れ・・・

#A - Dodecagon

	private void solveA() {
		int n = nextInt();
 
		out.println(3 * n * n);
	}

#B - Golden Apple


	/**
	 * 6 2
	 * 1 2 3 4 5 6
	 * - - ^ - -
	 *   - - ^ - -
	 *
	 * 20 4
	 * 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
	 *  -  -  -  -  ^  -  -  -  -
	 *                             -  -  -  -  ^  -  -  -  -
	 *                                   -  -  -  -  ^  -  -  -  -
	 */
	private void solveB() {
		int n = nextInt();
		int d = nextInt();
		int d2 = 2 * d + 1;
		int res = (n / d2) + ((n % d2) != 0 ? 1 : 0);
		out.println(res);
	}

#C - Exception Handling

最大値または、2番目に大きい値を出力すればよい
配列コピーして対応したけど。。。


	private void solveC() {
		int n = nextInt();
		int[] wk = IntStream.range(0, n).map(i -> nextInt()).toArray();
		int[] copy = Arrays.copyOf(wk, n);
		Arrays.sort(copy);
		int max = copy[n - 1];
		for (int i : wk) {
			if (i < max)
				out.println(max);
			else
				out.println(copy[n - 2]);
		}
	}

#D - Preparing Boxes

最初はすべての箱にボールが入っていない。
番号ごとに偶奇が合えばよい。
前から決定していくのは難しそうなので後ろから決定していけばいいのでは?と考えて実装。
後ろからなら倍数が存在しない数値があるので決定しやすい。
例えば、例1なら3番目の値を先に決定してしまう。
3番目の倍数の6は存在しないので決定可能。
1番目から決定していくと、1,2,3...と決定できない?感じ。


	private void solveD() {
		int n = nextInt();
		int[] wk = IntStream.range(0, n).map(i -> nextInt()).toArray();
 
		int cnt = 0;
		int[] res = new int[n];
		//後ろから決定
		for (int i = n; i > 0; i--) {
 
			final int target = wk[i - 1];
			int wkSum = 0;
			//倍数のボールの個数を数える
			for (int j = 2; (j * i - 1) < n; j++) {
				wkSum += res[j * i - 1];
			}
			//個数の偶奇
			if (target != (wkSum % 2)) {
				res[i - 1]++;
				cnt++;
			}
		}
 
		out.println(cnt);
		if (cnt != 0) {
			StringBuilder builder = new StringBuilder();
			for (int i = 0; i < res.length; i++) {
				if (res[i] != 0) {
					builder.append(i + 1).append(" ");
				}
			}
			out.println(builder.toString());
		}
	}	
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?