結果

問題 No.689 E869120 and Constructing Array 3
ユーザー tentententen
提出日時 2021-03-10 10:19:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 1,653 bytes
コンパイル時間 3,760 ms
コンパイル使用メモリ 77,432 KB
実行使用メモリ 37,040 KB
最終ジャッジ日時 2024-04-20 06:31:58
合計ジャッジ時間 4,467 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
36,772 KB
testcase_01 AC 52 ms
36,600 KB
testcase_02 AC 54 ms
36,844 KB
testcase_03 AC 55 ms
36,600 KB
testcase_04 AC 58 ms
36,892 KB
testcase_05 AC 57 ms
36,968 KB
testcase_06 AC 56 ms
36,808 KB
testcase_07 AC 58 ms
36,844 KB
testcase_08 AC 55 ms
36,608 KB
testcase_09 AC 54 ms
36,880 KB
testcase_10 AC 55 ms
36,800 KB
testcase_11 AC 55 ms
37,040 KB
testcase_12 AC 51 ms
36,936 KB
testcase_13 AC 51 ms
36,876 KB
testcase_14 AC 53 ms
36,776 KB
testcase_15 AC 54 ms
36,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int k = Integer.parseInt(br.readLine());
        if (k == 0) {
            System.out.println(1);
            System.out.println(1);
            return;
        }
        for (int i = 1; i * i <= k; i++) {
            for (int j = i; i * j <= k && i + j <= 250; j++) {
                int x = k - i * j;
                if (x == 0) {
                    output(i, j, 0, 0);
                    return;
                }
                for (int a = 1; a * a <= x; a++) {
                    if (x % a == 0) {
                        int b = x / a;
                        if (i + j + a + b <= 250) {
                            output(i, j, a, b);
                            return;
                        }
                    }
                }
            }
        }
    }
    
    static void output(int a, int b, int c, int d) {
        int n = a + b + c + d;
        StringBuilder sb = new StringBuilder();
        sb.append(n).append("\n");
        for (int i = 0; i < a; i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(4);
        }
        for (int i = 0; i < b; i++) {
            sb.append(" ");
            sb.append(9);
        }
        for (int i = 0; i < c; i++) {
            sb.append(" ");
            sb.append(6);
        }
        for (int i = 0; i < d; i++) {
            sb.append(" ");
            sb.append(11);
        }
        System.out.println(sb);
    }
}
0