結果

問題 No.689 E869120 and Constructing Array 3
ユーザー YamaKasaYamaKasa
提出日時 2018-05-19 02:07:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 1,000 ms
コード長 1,575 bytes
コンパイル時間 2,788 ms
コンパイル使用メモリ 73,940 KB
実行使用メモリ 58,224 KB
最終ジャッジ日時 2023-09-10 23:35:21
合計ジャッジ時間 6,109 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,032 KB
testcase_01 AC 129 ms
56,588 KB
testcase_02 AC 128 ms
55,880 KB
testcase_03 AC 128 ms
55,780 KB
testcase_04 AC 133 ms
55,868 KB
testcase_05 AC 134 ms
55,828 KB
testcase_06 AC 133 ms
58,224 KB
testcase_07 AC 133 ms
56,232 KB
testcase_08 AC 132 ms
56,136 KB
testcase_09 AC 132 ms
55,744 KB
testcase_10 AC 133 ms
55,776 KB
testcase_11 AC 133 ms
55,632 KB
testcase_12 AC 133 ms
55,976 KB
testcase_13 AC 121 ms
55,664 KB
testcase_14 AC 124 ms
56,020 KB
testcase_15 AC 124 ms
55,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		scan.close();
		int min = K;
		int a = 0;
		int b = 0;
		for(int i = 1; i <= 110; i++) {
			for(int j = 1; j <= 110; j++) {
				int k = i * j;
				if(k > 10000) {
					break;
				}else {
					int t = K - k;
					if(t >= 0) {
						if(min > t) {
							min = t;
							a = i;
							b = j;
						}
					}else {
						break;
					}
				}
			}
		}
		int c = K - a * b;
		if(c == 0) {
			System.out.println(a + b);
		}else {
			System.out.println(a + b + c + 1);
		}
		if(c == 0) {
			for(int i = 0; i < a; i++) {
				System.out.print(3 + " ");
			}
			for(int i = 0; i < b; i++) {
				if(i == b -1) {
					System.out.println(4);
				}else {
					System.out.print(4 + " ");
				}
			}

		}else {
			for(int i = 0; i < a; i++) {
				System.out.print(3 + " ");
			}
			for(int i = 0; i < b; i++) {
				System.out.print(4 + " ");
			}
			for(int i = 0; i < c; i++) {
				System.out.print(5 + " ");
			}
			System.out.println(6);
		}





//		Arrays.fill(r, 0);
//		int []k = new int[120 * 120];
//		Arrays.fill(k, 0);
//		int cnt = 0;
//		for(int i = 1; i <= 110; i++) {
//			for(int j = 1; j <= 110; j++) {
//				if(i * j > 10000) {
//					break;
//				}else {
//					k[cnt] = i * j;
//					cnt ++;
//				}
//			}
//		}
//		Arrays.sort(k);
//		int []l = new int[120 * 120 - 1];
//		for(int i = 0; i < 120 * 120 - 1; i++) {
//			l[i] = k[i + 1] - k[i];
//		}
//		Arrays.sort(l);
//		System.out.println(l[l.length - 1]);
	}
}
0