結果

問題 No.688 E869120 and Constructing Array 2
ユーザー バイトバイト
提出日時 2018-05-25 15:59:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 4,635 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 76,780 KB
実行使用メモリ 51,168 KB
最終ジャッジ日時 2023-09-21 20:43:07
合計ジャッジ時間 3,793 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
48,832 KB
testcase_01 AC 66 ms
50,884 KB
testcase_02 AC 67 ms
50,732 KB
testcase_03 AC 66 ms
50,664 KB
testcase_04 AC 67 ms
50,952 KB
testcase_05 AC 66 ms
50,640 KB
testcase_06 AC 66 ms
50,788 KB
testcase_07 AC 65 ms
50,676 KB
testcase_08 AC 65 ms
50,676 KB
testcase_09 AC 66 ms
50,692 KB
testcase_10 AC 66 ms
50,740 KB
testcase_11 AC 65 ms
51,168 KB
testcase_12 AC 66 ms
50,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

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

/**
 *
 * @author baito 
 */
public class Main
{
    static StringBuilder sb = new StringBuilder();
    static FastScanner sc = new FastScanner(System.in);
    public static void main(String[] args)
    {
        
        long N = sc.nextLong();
        long ans = 1;
        
        for (int n1 = 1; n1 <= 30; n1++) {
            for (int n0 = 0; (n0 + n1 ) <= 30; n0++) {
                ans *= n1 * (n1 - 1) / 2;
                ans *= Math.pow(2, n0);
                if(ans == N){
                    priAns(n1,n0);
                    return;
                }
                ans = 1;
            }
            
        }
        
        
    }
    private static void priAns(int n1, int n0) {
        sb.append(""+(n1 + n0)+"\n");
        for (int i = 0; i < n1; i++) {
            sb.append("1 ");
        }
        for (int i = 0; i < n0 - 1; i++) {
            sb.append("0 ");
        }
        if(n0 > 0){
            sb.append("0");
        }
        System.out.println(sb);
    }
    
    static int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); }
    static long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); }
	
    static <T> void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; }
    static void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; }
    
    static class FastScanner {

        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        
        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        /*public String nextChar(){
            return (char)next()[0];
        }*/
        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            
            return tokenizer.nextToken("\n");
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }
        public int [][] nextIntArray2(int h, int w){
            int[][] a = new int[h][w];
            for(int hi = 0 ; hi < h ; hi++){
                for(int wi = 0 ; wi < w ; wi++){
                    a[hi][wi] = nextInt();
                }
            }
            return a;
        }
        public char[] nextCharArray(int n){
            char[] a = next().toCharArray();
            
            return a;
        }
        public char[][] nextCharArray2(int h , int w){
            char[][] a = new char[h][w];
            for (int i = 0; i < h; i++) {
                a[i] = next().toCharArray();
            }
            return a;
        }
        public char[][] nextWrapCharArray2(int h , int w){
            char[][] a = new char[h + 2][w + 2];
            
            for (int i = 1; i < h + 1; i++) {
                a[i] = (" " + next() + " ").toCharArray();
            }
            return a;
        }
        
        
       
        
        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
        public long [][] nextLongArray2(int h, int w){
            long[][] a = new long[h][w];
            for(int hi = 0 ; hi < h ; hi++){
                for(int wi = 0 ; wi < h ; wi++){
                    a[h][w] = nextLong();
                }
            }
            return a;
        }
    }
}
0