結果

問題 No.355 数当てゲーム(2)
ユーザー mitsuomitsuo
提出日時 2016-05-04 16:36:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 1,873 bytes
コンパイル時間 3,644 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 76,036 KB
平均クエリ数 5.50
最終ジャッジ日時 2023-09-23 23:50:29
合計ジャッジ時間 15,268 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
73,820 KB
testcase_01 AC 198 ms
73,376 KB
testcase_02 AC 185 ms
73,692 KB
testcase_03 AC 201 ms
75,484 KB
testcase_04 AC 202 ms
75,080 KB
testcase_05 AC 205 ms
75,616 KB
testcase_06 AC 188 ms
75,148 KB
testcase_07 AC 196 ms
73,556 KB
testcase_08 AC 186 ms
73,644 KB
testcase_09 AC 186 ms
73,844 KB
testcase_10 AC 189 ms
75,560 KB
testcase_11 AC 205 ms
75,252 KB
testcase_12 AC 199 ms
75,544 KB
testcase_13 AC 188 ms
74,060 KB
testcase_14 AC 187 ms
73,348 KB
testcase_15 AC 195 ms
73,788 KB
testcase_16 AC 192 ms
75,080 KB
testcase_17 AC 203 ms
75,344 KB
testcase_18 AC 205 ms
74,188 KB
testcase_19 AC 203 ms
73,396 KB
testcase_20 AC 198 ms
75,188 KB
testcase_21 AC 197 ms
73,212 KB
testcase_22 AC 188 ms
75,376 KB
testcase_23 AC 186 ms
73,528 KB
testcase_24 AC 189 ms
73,860 KB
testcase_25 AC 199 ms
75,244 KB
testcase_26 AC 195 ms
75,816 KB
testcase_27 AC 196 ms
73,728 KB
testcase_28 AC 205 ms
75,416 KB
testcase_29 AC 205 ms
75,484 KB
testcase_30 AC 192 ms
73,544 KB
testcase_31 AC 215 ms
75,360 KB
testcase_32 AC 191 ms
73,080 KB
testcase_33 AC 201 ms
73,308 KB
testcase_34 AC 188 ms
73,448 KB
testcase_35 AC 205 ms
73,484 KB
testcase_36 AC 203 ms
74,868 KB
testcase_37 AC 201 ms
75,172 KB
testcase_38 AC 197 ms
75,508 KB
testcase_39 AC 202 ms
73,720 KB
testcase_40 AC 213 ms
75,872 KB
testcase_41 AC 204 ms
75,212 KB
testcase_42 AC 189 ms
73,464 KB
testcase_43 AC 200 ms
75,124 KB
testcase_44 AC 190 ms
75,412 KB
testcase_45 AC 202 ms
75,244 KB
testcase_46 AC 191 ms
73,776 KB
testcase_47 AC 193 ms
76,036 KB
testcase_48 AC 199 ms
72,984 KB
testcase_49 AC 198 ms
73,804 KB
testcase_50 AC 198 ms
75,556 KB
testcase_51 AC 197 ms
73,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main().solve();
	}

	public void solve() {
		List<int[]> candidate = new ArrayList<int[]>();
		for (int j = 0; j < 10000; j++) {
			int c1 = j % 10;
			int c2 = j / 10 % 10;
			int c3 = j / 100 % 10;
			int c4 = j / 1000 % 10;
			if (c1 == c2 || c1 == c3 || c1 == c3 || c1 == c4 || c2 == c3 || c2 == c4 || c3 == c4) {
				continue;
			} else {
				int[] r = new int[4];
				r[0] = c1;
				r[1] = c2;
				r[2] = c3;
				r[3] = c4;
				candidate.add(r);
			}
		}
		while (candidate.size() > 1) {
			int[] c = candidate.get(0);
			send(c);
			String input = get();
			if (input.equals("4 0")) {
				return;
			} else {
				candidate.remove(0);
				List<Integer> rm = new ArrayList<>();
				for (int i = 0; i < candidate.size(); i++) {
					if (isContradiction(candidate.get(i), input, c)) {
//						System.out.println("remove " + toS(candidate.get(i)));
						rm.add(i);
						candidate.remove(i);
						i--;
					}
				}
//				System.out.println(candidate.size());
			}
		}
		send(candidate.get(0));

	}

	private String toS(int[] c) {
		return (c[0] + " " + c[1] + " " + c[2] + " " + c[3]);
	}

	private void send(int[] c) {
		send(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);
	}

	private boolean isContradiction(int[] can, String input, int[] ans) {

		int m1 = 0;
		int m2 = 0;

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (ans[i] == can[j]) {
					m2++;
				}
			}
		}
		for (int i = 0; i < 4; i++) {
			if (ans[i] == can[i]) {
				m1++;
				m2--;
			}
		}
		return ! input.equals(m1 + " " + m2);
	}

	protected void send(String s) {
		System.out.println(s);
		System.out.flush();

	}

	protected String get() {
		return sc.nextLine();
	}

}
0