結果

問題 No.1837 Same but Different
ユーザー ks2m
提出日時 2022-02-11 23:09:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 1,289 bytes
コンパイル時間 3,379 ms
コンパイル使用メモリ 79,228 KB
実行使用メモリ 41,816 KB
最終ジャッジ日時 2024-06-27 21:15:10
合計ジャッジ時間 7,820 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		List<Integer> a = new ArrayList<>();
		int ta = 0;
		if (n % 3 == 1) {
			a.add(3);
			ta += 3;
		}
		if (n % 3 == 2) {
			a.add(6);
			a.add(9);
			ta += 15;
		}
		int x = 15;
		while (a.size() < n) {
			a.add(x);
			ta += x;
			x += 3;
		}

		List<Integer> b = new ArrayList<>();
		int tb = 0;
		if (n % 3 == 1) {
			b.add(0);
		}
		if (n % 3 == 2) {
			b.add(0);
			b.add(3);
			tb += 3;
		}
		int y = 13;
		if (n == 5 || n == 8 || n == 11 || n == 14) {
			y = 16;
		}
		while (b.size() <= n) {
			b.add(y);
			tb += y;
			y += 3;
		}

		int xa = 0;
		StringBuilder sb = new StringBuilder();
		for (int i : a) {
			sb.append(i).append(' ');
			xa += i;
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());

		int rem = tb - ta;
		int xb = 0;
		int cnt = 0;
		sb = new StringBuilder();
		for (int i : b) {
			if (i != rem) {
				sb.append(i).append(' ');
				xb += i;
				cnt++;
			}
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
		if (xa != xb || cnt != n) {
			throw new Exception();
		}
	}
}
0