結果

問題 No.355 数当てゲーム(2)
ユーザー GrenacheGrenache
提出日時 2016-04-02 20:08:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 3,062 bytes
コンパイル時間 4,269 ms
コンパイル使用メモリ 76,356 KB
実行使用メモリ 73,648 KB
平均クエリ数 5.52
最終ジャッジ日時 2023-09-23 23:37:46
合計ジャッジ時間 13,629 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
71,856 KB
testcase_01 AC 138 ms
72,116 KB
testcase_02 AC 143 ms
71,688 KB
testcase_03 AC 146 ms
72,488 KB
testcase_04 AC 144 ms
70,220 KB
testcase_05 AC 135 ms
72,348 KB
testcase_06 AC 158 ms
72,192 KB
testcase_07 AC 146 ms
71,564 KB
testcase_08 AC 147 ms
71,484 KB
testcase_09 AC 148 ms
71,068 KB
testcase_10 AC 149 ms
71,500 KB
testcase_11 AC 149 ms
71,120 KB
testcase_12 AC 148 ms
71,904 KB
testcase_13 AC 146 ms
70,948 KB
testcase_14 AC 148 ms
71,996 KB
testcase_15 AC 143 ms
71,404 KB
testcase_16 AC 135 ms
69,872 KB
testcase_17 AC 146 ms
71,516 KB
testcase_18 AC 146 ms
72,040 KB
testcase_19 AC 149 ms
71,888 KB
testcase_20 AC 152 ms
71,660 KB
testcase_21 AC 151 ms
70,948 KB
testcase_22 AC 179 ms
71,244 KB
testcase_23 AC 154 ms
72,240 KB
testcase_24 AC 152 ms
71,916 KB
testcase_25 AC 136 ms
70,828 KB
testcase_26 AC 146 ms
73,492 KB
testcase_27 AC 155 ms
71,892 KB
testcase_28 AC 146 ms
71,596 KB
testcase_29 AC 147 ms
71,504 KB
testcase_30 AC 147 ms
72,304 KB
testcase_31 AC 137 ms
71,712 KB
testcase_32 AC 145 ms
71,436 KB
testcase_33 AC 146 ms
72,096 KB
testcase_34 AC 146 ms
72,260 KB
testcase_35 AC 137 ms
71,268 KB
testcase_36 AC 158 ms
72,028 KB
testcase_37 AC 147 ms
71,736 KB
testcase_38 AC 139 ms
72,036 KB
testcase_39 AC 146 ms
72,260 KB
testcase_40 AC 146 ms
71,764 KB
testcase_41 AC 149 ms
71,928 KB
testcase_42 AC 145 ms
73,648 KB
testcase_43 AC 146 ms
71,876 KB
testcase_44 AC 157 ms
71,260 KB
testcase_45 AC 147 ms
71,876 KB
testcase_46 AC 137 ms
71,148 KB
testcase_47 AC 152 ms
72,576 KB
testcase_48 AC 139 ms
71,892 KB
testcase_49 AC 152 ms
71,640 KB
testcase_50 AC 138 ms
71,168 KB
testcase_51 AC 149 ms
72,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder355 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        Queue<List<Integer>> q = new ArrayDeque<>();
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
            	if (i == j) {
            		continue;
            	}
                for (int k = 0; k < 10; k++) {
                	if (k == i || k == j) {
                		continue;
                	}
                    for (int l = 0; l < 10; l++) {
                    	if (l == i || l == j || l == k) {
                    		continue;
                    	}

                    	ArrayList<Integer> tmp = new ArrayList<>();
                    	tmp.add(i);
                    	tmp.add(j);
                    	tmp.add(k);
                    	tmp.add(l);
                    	q.add(tmp);
                    }
                }
            }
        }

        while (!q.isEmpty()) {
//        	pr.println(q.size());
        	List<Integer> e = q.remove();

        	send(e, pr);
        	int x = sc.nextInt();
        	int y = sc.nextInt();
    		if (x == 4 && y == 0) {
    			break;
    		}

    		Queue<List<Integer>> qtmp = new ArrayDeque<>();
    		for (List<Integer> ee : q) {
    			if (eq(e, ee, x, y)) {
    				qtmp.add(ee);
    			}
    		}

    		q = qtmp;
        }

        pr.close();
        sc.close();
    }

	private static boolean eq(List<Integer> e, List<Integer> ee, int x, int y) {
		int xtmp = 0;
		int ytmp = 0;
		for (int i = 0; i < e.size(); i++) {
			for (int j = 0; j < e.size(); j++) {
				if (e.get(i) == ee.get(j)) {
					if (i == j) {
						xtmp++;
					} else {
						ytmp++;
					}
				}
			}
		}

		if (x == xtmp && y == ytmp) {
			return true;
		} else {
			return false;
		}
	}

	private static void send(List<Integer> num, Printer pr) {
		pr.printf("%d %d %d %d\n", num.get(0), num.get(1), num.get(2), num.get(3));
		pr.flush();

		return;
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0