結果

問題 No.355 数当てゲーム(2)
ユーザー matsuyoshi30matsuyoshi30
提出日時 2016-04-02 08:55:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,531 bytes
コンパイル時間 3,954 ms
コンパイル使用メモリ 79,968 KB
実行使用メモリ 73,832 KB
平均クエリ数 38.87
最終ジャッジ日時 2023-09-23 23:34:47
合計ジャッジ時間 12,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
72,020 KB
testcase_01 AC 151 ms
72,428 KB
testcase_02 AC 159 ms
71,332 KB
testcase_03 AC 149 ms
71,776 KB
testcase_04 AC 149 ms
71,972 KB
testcase_05 AC 150 ms
72,256 KB
testcase_06 AC 156 ms
71,592 KB
testcase_07 AC 145 ms
71,564 KB
testcase_08 AC 156 ms
71,752 KB
testcase_09 AC 148 ms
72,004 KB
testcase_10 AC 144 ms
71,792 KB
testcase_11 AC 145 ms
72,176 KB
testcase_12 AC 144 ms
72,044 KB
testcase_13 AC 152 ms
71,732 KB
testcase_14 AC 142 ms
71,892 KB
testcase_15 AC 145 ms
69,784 KB
testcase_16 AC 145 ms
72,124 KB
testcase_17 AC 149 ms
71,628 KB
testcase_18 AC 149 ms
71,768 KB
testcase_19 AC 155 ms
72,296 KB
testcase_20 AC 150 ms
72,084 KB
testcase_21 AC 147 ms
72,296 KB
testcase_22 AC 145 ms
72,156 KB
testcase_23 AC 142 ms
71,608 KB
testcase_24 AC 155 ms
71,592 KB
testcase_25 AC 160 ms
73,832 KB
testcase_26 AC 158 ms
72,112 KB
testcase_27 AC 149 ms
71,728 KB
testcase_28 AC 148 ms
71,260 KB
testcase_29 AC 155 ms
71,568 KB
testcase_30 AC 148 ms
71,764 KB
testcase_31 AC 144 ms
72,248 KB
testcase_32 AC 152 ms
72,508 KB
testcase_33 AC 156 ms
70,456 KB
testcase_34 AC 149 ms
71,920 KB
testcase_35 AC 129 ms
71,696 KB
testcase_36 AC 143 ms
72,180 KB
testcase_37 AC 152 ms
72,208 KB
testcase_38 AC 146 ms
72,364 KB
testcase_39 AC 153 ms
72,192 KB
testcase_40 AC 145 ms
71,920 KB
testcase_41 AC 144 ms
71,928 KB
testcase_42 AC 137 ms
71,864 KB
testcase_43 AC 139 ms
72,700 KB
testcase_44 AC 141 ms
72,072 KB
testcase_45 AC 139 ms
71,300 KB
testcase_46 AC 145 ms
71,380 KB
testcase_47 AC 141 ms
71,672 KB
testcase_48 AC 147 ms
69,596 KB
testcase_49 AC 141 ms
72,272 KB
testcase_50 AC 158 ms
72,008 KB
testcase_51 AC 127 ms
71,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {

	static int[] query = new int[4];
	static int hit = 0;
	static int bite = 0;

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		for(int i=0; i<4; i++) {
			query[i] = i;
		}
		query();
		for(int i=0; i<4; i++) {
			int best = -1;
			int best_j = -1;
			for(int j=0; j<=9; j++) {
				query[i] = j;
				if(!isValid()) {
					continue;
				}
				query();
				if(hit + bite > best) {
					best = hit + bite;
					best_j = j;
				}
			}
			query[i] = best_j;
		}
		Arrays.sort(query);
		do {
			query();
		} while(nextP(query));
	}

	public static boolean isValid() {
		boolean[] used = new boolean[10];
		for(int i=0; i<4; i++) {
			int x = query[i];
			if(used[x]) {
				return false;
			}
			used[x] = true;
		}
		return true;
	}

	public static void query() {
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<4; i++) {
			if(i > 0) {
				sb.append(' ');
			}
			sb.append(query[i]);
		}
		System.out.println(sb.toString());
		hit = in.nextInt();
		bite = in.nextInt();
		if(hit == 4) {
			System.exit(0);
		}
	}

	static boolean nextP(int[] p) {
		for(int a=p.length-2; a>=0; --a) {
			if(p[a] < p[a+1]) {
				for(int b=p.length-1;;--b) {
					if(p[b] > p[a]) {
						int temp = p[a];
						p[a] = p[b];
						p[b] = temp;
						for(++a, b=p.length-1; a<b; ++a, --b) {
							temp = p[a];
							p[a] = p[b];
							p[b] = temp;
						}
						return true;
					}
				}
			}
		}
		return false;
	}

}
0