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 5 years have passed since last update.

ABC - 050- A&B&C

Last updated at Posted at 2019-04-03

AtCoder ABC 050 A&B&C

AtCoder - 050

2019/05/27
 問題名修正
 B問題のコードの書き方を修正 int[][]の生成部分

A - Addition and Subtraction Easy

  • operandをcharで判定して $\pm$ する
	private void solveA() {
		int numA = nextInt();
		char operand = next().charAt(0);
		int numB = nextInt();

		int res = operand == '+' ? numA + numB : numA - numB;

		out.println(res);
	}

B - Contest with Drinks Easy

  • 全てのパターンでforをするのは時間が間に合わないので
    • 薬を飲まない場合の総時間を算出しておく
    • 薬$P_i$を飲んだ場合、$T_i$と$X_i$の差分を総時間から引くようにする
	private void solveB() {
		int numN = nextInt();
		int[] arrayT = IntStream.range(0, numN).map(i -> nextInt()).toArray();
		long sumT = Arrays.stream(arrayT).sum();
		//		int[] arrayT = new int[numN];
		//		long sumT = 0;
		//		for (int j = 0; j < numN; j++) {
		//			arrayT[j] = nextInt();
		//			sumT += arrayT[j];
		//		}
		int numM = nextInt();
		int[][] arrayPX = Stream.generate(() -> new int[] { nextInt(), nextInt() }).limit(numM).toArray(int[][]::new);
		//		int[][] arrayPX = IntStream.range(0, numM).collect(() -> new int[numM][2], (t, i) -> {
		//			t[i][0] = nextInt();
		//			t[i][1] = nextInt();
		//		}, (t, u) -> {
		//			Stream.concat(Arrays.stream(t), Arrays.stream(u)).toArray();
		//		});

		for (int[] js : arrayPX) {
			long res = (sumT - arrayT[js[0] - 1]) + js[1];
			out.println(res);
		}
	}

C - Lining Up

  • 隣にいるという意味を以下に示す

奇数人

1人目 2人目 3人目 4人目 5人目 6人目
両隣の人数の差分 5 3 1 1 3 5

偶数人

1人目 2人目 3人目 4人目 5人目 6人目 7人目
両隣の人数の差分 6 4 2 0 2 4 6
	private void solveC() {
		int numN = nextInt();
		int[] wk = IntStream.range(0, numN).map(i -> nextInt()).toArray();

		int size = numN - 1;
		int min = 0;
		int max = 0;
		int cntVal = 0;
		int totalCount = 0;

		Arrays.sort(wk);

		if (numN % 2 == 0) {
			if (wk[0] != 1) {
				out.println(0);
				return;
			}
			min = 0;
			max = wk.length - 1;
			cntVal = 1;
		} else {
			if (wk[0] != 0) {
				out.println(0);
				return;
			}
			min = 1;
			max = wk.length;
			cntVal = 2;
		}

		for (int i = min; i < max; i = i + 2) {
			if (wk[i] == wk[i + 1] && wk[i] == cntVal) {
				totalCount++;
			} else {
				out.println(0);
				return;
			}
			cntVal += 2;
		}

		final long CONST = (long) Math.pow(10, 9) + 7;

		long res = LongStream.range(0, totalCount).reduce(1, (sum, i) -> {
			sum = (sum * 2) % CONST;
			return sum % CONST;
		});
		out.println(res);

	}
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?