結果

問題 No.501 穴と文字列
ユーザー hhgfhn1hhgfhn1
提出日時 2018-11-18 23:31:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,446 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 5,641 ms
コンパイル使用メモリ 71,568 KB
実行使用メモリ 56,384 KB
最終ジャッジ日時 2023-08-26 02:01:59
合計ジャッジ時間 14,725 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,176 ms
56,060 KB
testcase_01 AC 1,140 ms
56,384 KB
testcase_02 AC 123 ms
56,288 KB
testcase_03 AC 122 ms
55,996 KB
testcase_04 AC 123 ms
55,556 KB
testcase_05 AC 122 ms
55,896 KB
testcase_06 AC 123 ms
55,876 KB
testcase_07 AC 124 ms
53,776 KB
testcase_08 AC 123 ms
55,900 KB
testcase_09 AC 122 ms
55,828 KB
testcase_10 AC 122 ms
55,956 KB
testcase_11 AC 123 ms
56,004 KB
testcase_12 AC 121 ms
54,204 KB
testcase_13 AC 125 ms
55,808 KB
testcase_14 AC 124 ms
55,792 KB
testcase_15 AC 125 ms
56,092 KB
testcase_16 AC 123 ms
56,160 KB
testcase_17 AC 122 ms
55,956 KB
testcase_18 AC 1,442 ms
56,208 KB
testcase_19 AC 1,439 ms
55,740 KB
testcase_20 AC 1,446 ms
55,828 KB
testcase_21 AC 1,439 ms
55,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n=scanner.nextInt();
		int d=scanner.nextInt();
		int max=Integer.MIN_VALUE;
		int a=0;
		int b=0;
		int c=0;
		for(int i=0;i<=n;i++) {
			for(int j=0;i+j<=n;j++) {
				int k=n-i-j;
				if(i*0+j*1+k*2==d) {
					if(max<j) {
						max=j;
						a=j;
						b=k;
						c=i;
					}
				}
			}
		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<a;i++) {
			sb.append("A");
		}
		for(int i=0;i<b;i++) {
			sb.append("B");
		}
		for(int i=0;i<c;i++) {
			sb.append("C");
		}
		System.out.println(sb);
	}
}
0