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

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

E / F is out of time ...

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

The maximum value or the second largest value should be output. I copied the array and responded. .. ..


	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

Initially there are no balls in all the boxes. Even or oddness should match for each number. It seems difficult to decide from the front, so why not decide from the back? I thought and implemented it. From the back, it is easy to determine because there are numerical values that do not have multiples. For example, in Example 1, the third value is determined first. The third multiple, 6, does not exist, so it can be determined. If you decide from the first, can't you decide 1,2,3 ...? Feeling.


	private void solveD() {
		int n = nextInt();
		int[] wk = IntStream.range(0, n).map(i -> nextInt()).toArray();
 
		int cnt = 0;
		int[] res = new int[n];
		//Determined from behind
		for (int i = n; i > 0; i--) {
 
			final int target = wk[i - 1];
			int wkSum = 0;
			//Count the number of multiple balls
			for (int j = 2; (j * i - 1) < n; j++) {
				wkSum += res[j * i - 1];
			}
			//Number of evens and odds
			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());
		}
	}	

Recommended Posts

ABC --134- A & B & C & D & E
ABC --131- A & B & C & D & E
ABC --129- A & B & C & D
ABC --133- A & B & C & D
ABC --122 --A & B & C & D
ABC --125- A & B & C & D
ABC --130- A & B & C & D
ABC --126 --A & B & C & D
ABC --013-A & B & C
ABC --023 --A & B & C
ABC --036-A & B & C
ABC --010 --A & B & C
ABC --028 --A & B & C
ABC --015 --A & B & C
ABC --128 --A & B & C
ABC --012-A & B & C
ABC --018 --A & B & C
ABC --054 --A & B & C
ABC --017 --A & B & C
ABC --029- A & B & C
ABC --022 --A & B & C
ABC --019 --A & B & C
ABC --020 --A & B & C
ABC --030- A & B & C
ABC --127 --A & B & C
ABC --007 --A & B & C
ABC --132- A & B & C
ABC --026 --A & B & C
ABC --014- A & B & C
ABC --016 --A & B & C
ABC --011-A & B & C
ABC --031 --A & B & C
ABC --021 --A & B & C
ABC --025 --A & B & C
ABC --024 --A & B & C
ABC --027 --A & B & C
ABC --080- A & B & C
diverta 2019 Programming Contest A & B & C & D
AtCoder Beginner Contest 169 A, B, C with ruby
atcoder ABC113 C problem
atcoder ABC70 D problem
ABC093 C --Same Integers
AtCoder Beginner Contest 170 A, B, C up to ruby
atcoder ABC115 C problem
ABC177 --solving E in Ruby