結果
問題 | No.501 穴と文字列 |
ユーザー |
![]() |
提出日時 | 2018-11-18 23:37:10 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 182 ms / 2,000 ms |
コード長 | 769 bytes |
コンパイル時間 | 2,891 ms |
コンパイル使用メモリ | 77,520 KB |
実行使用メモリ | 41,484 KB |
最終ジャッジ日時 | 2024-12-24 15:11:13 |
合計ジャッジ時間 | 7,290 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
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); } }