結果
問題 | No.689 E869120 and Constructing Array 3 |
ユーザー |
![]() |
提出日時 | 2023-01-31 14:12:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 64 ms / 1,000 ms |
コード長 | 2,745 bytes |
コンパイル時間 | 4,030 ms |
コンパイル使用メモリ | 87,092 KB |
実行使用メモリ | 52,716 KB |
最終ジャッジ日時 | 2023-09-13 07:26:45 |
合計ジャッジ時間 | 6,260 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,488 KB |
testcase_01 | AC | 44 ms
49,560 KB |
testcase_02 | AC | 42 ms
49,444 KB |
testcase_03 | AC | 42 ms
49,612 KB |
testcase_04 | AC | 44 ms
49,408 KB |
testcase_05 | AC | 52 ms
50,900 KB |
testcase_06 | AC | 55 ms
50,928 KB |
testcase_07 | AC | 57 ms
50,960 KB |
testcase_08 | AC | 63 ms
51,720 KB |
testcase_09 | AC | 62 ms
52,716 KB |
testcase_10 | AC | 62 ms
51,808 KB |
testcase_11 | AC | 64 ms
51,960 KB |
testcase_12 | AC | 62 ms
51,668 KB |
testcase_13 | AC | 42 ms
49,748 KB |
testcase_14 | AC | 43 ms
49,584 KB |
testcase_15 | AC | 42 ms
49,872 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int k = sc.nextInt(); int[] counts = new int[k + 1]; int[] lefts = new int[k + 1]; int[] rights = new int[k + 1]; for (int i = 1; i <= k; i++) { for (int j = 1; j <= Math.sqrt(i); j++) { if (i % j == 0) { counts[i] = j + i / j; lefts[i] = j; rights[i] = i / j; } } } ArrayList<Integer> ans = new ArrayList<>(); for (int i = 0; i <= k / 2; i++) { if (counts[i] + counts[k - i] <= 250) { for (int j = 0; j < lefts[i]; j++) { ans.add(3); } for (int j = 0; j < rights[i]; j++) { ans.add(4); } for (int j = 0; j < lefts[k - i]; j++) { ans.add(5); } for (int j = 0; j < rights[k - i]; j++) { ans.add(6); } break; } } System.out.println(ans.size()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < ans.size(); i++) { if (i > 0) { sb.append(" "); } sb.append(ans.get(i)); } System.out.println(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }