結果

問題 No.305 鍵(2)
ユーザー 14番14番
提出日時 2016-05-16 14:33:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 2,657 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 70,220 KB
平均クエリ数 31.00
最終ジャッジ日時 2023-09-23 23:53:21
合計ジャッジ時間 5,048 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
69,304 KB
testcase_01 AC 112 ms
69,132 KB
testcase_02 AC 112 ms
68,164 KB
testcase_03 AC 124 ms
69,140 KB
testcase_04 AC 117 ms
69,812 KB
testcase_05 AC 67 ms
65,716 KB
testcase_06 AC 66 ms
65,192 KB
testcase_07 AC 113 ms
69,932 KB
testcase_08 AC 112 ms
69,312 KB
testcase_09 AC 113 ms
69,336 KB
testcase_10 AC 114 ms
69,168 KB
testcase_11 AC 125 ms
69,672 KB
testcase_12 AC 115 ms
70,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;

public class Main {

	public BufferedReader br;

	/**
	 * メイン処理
	 * @throws IOException
	 */
	public void Proc() throws IOException {
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		int minCount = Integer.MAX_VALUE;
		for(int i=0; i<=9; i++) {
			System.out.println(this.DupChar(10, "" + i));
			String[] ret = br.readLine().split(" ");
			int cnt = Integer.parseInt(ret[0]);
			if(cnt == 10) {
				return;
			}
			map.put(i, cnt);
			minCount = Math.min(minCount, cnt);
		}
		Integer[] ans = new Integer[10];
		if(minCount == 0) {
			int umeNum = -1;
			for(Integer key : map.keySet()) {
				if(map.get(key).intValue() == 0) {
					umeNum = key.intValue();
					break;
				}
			}
			for(int i=0; i<=9; i++) {
				if(map.get(i).intValue() == 0) {
					continue;
				}
				for(int j=0; j<map.get(i).intValue(); j++) {
					for(int k=0; k<ans.length; k++) {
						if(ans[k] != null) {
							continue;
						}
						System.out.println(this.DupChar(k, "" + umeNum) + i + this.DupChar(10 - k - 1, "" + umeNum));
						String[] ret = br.readLine().split(" ");
						int cnt = Integer.parseInt(ret[0]);
						if(cnt == 10) {
							return;
						}
						if(cnt == 1) {
							ans[k] = i;
							break;
						}
					}
				}
			}

		} else {
			for(int i=0; i<=8; i++) {
				for(int j=0; j<ans.length; j++) {
					if(ans[j] != null) {
						continue;
					}
					System.out.println(this.DupChar(j, "9") + i + this.DupChar(10 - j - 1, "9"));
					String[] ret = br.readLine().split(" ");
					int cnt = Integer.parseInt(ret[0]);
					if(cnt == 10) {
						return;
					}
					if(cnt == 2) {
						ans[j] = i;
						break;
					}
				}
			}
			for(int i=0; i<ans.length; i++) {
				if(ans[i] == null) {
					ans[i] = 9;
					break;
				}
			}
		}
		StringBuilder ansStr = new StringBuilder();
		for(Integer num : ans) {
			ansStr.append(num.intValue());
		}
		System.out.println(ansStr.toString());
		String last = br.readLine();
		return;
	}

	private String DupChar (int len, String s) {
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<len; i++) {
			sb.append(s);
		}
		return sb.toString();
	}


	public static void main(String[] args)  {
		Main mn = new Main();
		mn.br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		try {
			mn.Proc();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		} finally {
			try {
				mn.br.close();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
		}
	}


}

0