結果

問題 No.501 穴と文字列
ユーザー hhgfhn1hhgfhn1
提出日時 2018-11-18 23:37:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 769 bytes
コンパイル時間 1,869 ms
コンパイル使用メモリ 74,092 KB
実行使用メモリ 56,740 KB
最終ジャッジ日時 2023-08-26 02:02:07
合計ジャッジ時間 5,528 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,680 KB
testcase_01 AC 117 ms
56,036 KB
testcase_02 AC 105 ms
55,916 KB
testcase_03 AC 112 ms
56,740 KB
testcase_04 AC 110 ms
56,000 KB
testcase_05 AC 106 ms
55,764 KB
testcase_06 AC 107 ms
56,196 KB
testcase_07 AC 111 ms
56,156 KB
testcase_08 AC 105 ms
55,888 KB
testcase_09 AC 106 ms
56,008 KB
testcase_10 AC 104 ms
55,680 KB
testcase_11 AC 107 ms
55,848 KB
testcase_12 AC 107 ms
56,248 KB
testcase_13 AC 104 ms
56,056 KB
testcase_14 AC 106 ms
56,012 KB
testcase_15 AC 107 ms
56,052 KB
testcase_16 AC 105 ms
55,528 KB
testcase_17 AC 104 ms
55,808 KB
testcase_18 AC 120 ms
56,144 KB
testcase_19 AC 122 ms
55,856 KB
testcase_20 AC 121 ms
56,104 KB
testcase_21 AC 123 ms
56,036 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();
		if(n>=d) {
			StringBuilder sb=new StringBuilder();
			for(int i=0;i<d;i++) {
				sb.append("A");
			}
			for(int i=0;i<n-d;i++) {
				sb.append("C");
			}
			System.out.println(sb);
			return;
		}
		int max=Integer.MIN_VALUE;
		int a=0;
		int b=0;
		for(int j=0;j<=n;j++) {
				int k=n-j;
				if(j*1+k*2==d) {
					if(max<j) {
						max=j;
						a=j;
						b=k;
					}
				}
			}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<a;i++) {
			sb.append("A");
		}
		for(int i=0;i<b;i++) {
			sb.append("B");
		}
		System.out.println(sb);
	}
}
0