結果

問題 No.688 E869120 and Constructing Array 2
ユーザー tentententen
提出日時 2023-02-15 16:22:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 45 ms / 1,000 ms
コード長 2,397 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 49,704 KB
最終ジャッジ日時 2023-09-25 01:08:12
合計ジャッジ時間 4,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,540 KB
testcase_01 AC 44 ms
49,512 KB
testcase_02 AC 44 ms
49,144 KB
testcase_03 AC 44 ms
49,400 KB
testcase_04 AC 45 ms
49,304 KB
testcase_05 AC 44 ms
49,704 KB
testcase_06 AC 43 ms
49,356 KB
testcase_07 AC 43 ms
49,408 KB
testcase_08 AC 44 ms
49,460 KB
testcase_09 AC 43 ms
49,184 KB
testcase_10 AC 42 ms
49,416 KB
testcase_11 AC 44 ms
49,228 KB
testcase_12 AC 44 ms
49,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        long[] aCount = new long[31];
        for (int i = 0; i <= 30; i++) {
            aCount[i] = (1 << i);
        }
        long[] bCount = new long[31];
        for (int i = 0; i <= 30; i++) {
            bCount[i] = i * (i - 1) / 2;
        }
        for (int i = 0; i <= 30; i++) {
            for (int j = 1; j <= 30 && j + i <= 30; j++) {
                if (aCount[i] * bCount[j] == k) {
                    System.out.println(i + j);
                    StringBuilder sb = new StringBuilder();
                    for (int a = 0; a < j; a++) {
                        if (a > 0) {
                            sb.append(" ");
                        }
                        sb.append("1");
                    }
                    for (int a = 0; a < i; a++) {
                        sb.append(" 0");
                    }
                    System.out.println(sb);
                    return;
                }
            }
        }
    }
}
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();
    }
    
}
0