結果
問題 | No.1837 Same but Different |
ユーザー | ks2m |
提出日時 | 2022-02-11 23:09:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 1,289 bytes |
コンパイル時間 | 3,473 ms |
コンパイル使用メモリ | 75,988 KB |
実行使用メモリ | 56,372 KB |
最終ジャッジ日時 | 2023-09-10 05:41:02 |
合計ジャッジ時間 | 9,022 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 125 ms
55,528 KB |
testcase_01 | AC | 123 ms
55,800 KB |
testcase_02 | AC | 123 ms
55,628 KB |
testcase_03 | AC | 128 ms
55,840 KB |
testcase_04 | AC | 158 ms
55,980 KB |
testcase_05 | AC | 155 ms
55,968 KB |
testcase_06 | AC | 159 ms
55,904 KB |
testcase_07 | AC | 149 ms
56,360 KB |
testcase_08 | AC | 158 ms
56,096 KB |
testcase_09 | AC | 158 ms
55,892 KB |
testcase_10 | AC | 160 ms
55,848 KB |
testcase_11 | AC | 158 ms
55,896 KB |
testcase_12 | AC | 157 ms
56,216 KB |
testcase_13 | AC | 147 ms
56,056 KB |
testcase_14 | AC | 156 ms
56,372 KB |
testcase_15 | AC | 133 ms
55,816 KB |
testcase_16 | AC | 128 ms
55,500 KB |
testcase_17 | AC | 129 ms
55,564 KB |
testcase_18 | AC | 134 ms
55,748 KB |
testcase_19 | AC | 131 ms
56,164 KB |
testcase_20 | AC | 130 ms
55,764 KB |
testcase_21 | AC | 133 ms
56,052 KB |
testcase_22 | AC | 130 ms
55,784 KB |
testcase_23 | AC | 128 ms
55,540 KB |
ソースコード
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(); } } }