結果

問題 No.83 最大マッチング
ユーザー eagleeagle
提出日時 2022-06-08 14:16:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 340 ms / 5,000 ms
コード長 1,255 bytes
コンパイル時間 5,103 ms
コンパイル使用メモリ 85,952 KB
実行使用メモリ 60,084 KB
最終ジャッジ日時 2023-10-21 04:02:23
合計ジャッジ時間 8,432 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,500 KB
testcase_01 AC 137 ms
57,140 KB
testcase_02 AC 137 ms
57,564 KB
testcase_03 AC 140 ms
57,704 KB
testcase_04 AC 138 ms
57,176 KB
testcase_05 AC 138 ms
57,484 KB
testcase_06 AC 137 ms
57,456 KB
testcase_07 AC 135 ms
57,508 KB
testcase_08 AC 138 ms
57,544 KB
testcase_09 AC 165 ms
59,944 KB
testcase_10 AC 251 ms
60,032 KB
testcase_11 AC 335 ms
60,084 KB
testcase_12 AC 340 ms
60,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//マッチの本数
		long N = sc.nextLong();
		//表記できる最大の数
		String pattern = "";
		//残りのマッチの数
		long match = N;
		//ループの終了条件
		boolean flg = true;
		while(flg) {
			//桁数が大きくなるようにパターンを作成する
			//1を作れるか
			if(match / 2 != 0 && match % 2 == 0) {
				//1を作成
				pattern += "1";
				match -= 2;
			//7を作れるか
			} else if(match / 3 != 0) {
				//7を作成
				pattern += "7";
				match -= 3;
			//4を作れるか
			} else if(match / 4 != 0) {
				//4を作成
				pattern += "4";
				match -= 4;
			//5を作れるか
			} else if(match / 5 != 0) {
				//5を作成
				pattern += "5";
				match -= 5;
			//9を作れるか
			} else if(match / 6 != 0) {
				//9を作成
				pattern += "9";
				match -= 6;
			//8を作れるか
			} else if(match / 7 != 0) {
				//8を作成
				pattern += "8";
				match -= 7;
			//何も作れない場合
			} else {
				//ループを終了
				flg = false;
			}
		}
		//答え出力
		System.out.println(pattern);
	}
}
0