結果

問題 No.624 Santa Claus and The Last Dungeon
ユーザー uwiuwi
提出日時 2018-01-02 04:00:44
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 3,815 bytes
コンパイル時間 3,785 ms
コンパイル使用メモリ 79,908 KB
実行使用メモリ 77,692 KB
平均クエリ数 483.25
最終ジャッジ日時 2023-09-23 15:28:57
合計ジャッジ時間 21,864 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 368 ms
75,844 KB
testcase_01 AC 370 ms
75,984 KB
testcase_02 AC 356 ms
77,692 KB
testcase_03 AC 361 ms
76,984 KB
testcase_04 AC 360 ms
75,600 KB
testcase_05 AC 368 ms
75,824 KB
testcase_06 AC 359 ms
75,784 KB
testcase_07 AC 371 ms
77,004 KB
testcase_08 AC 360 ms
76,572 KB
testcase_09 AC 362 ms
76,884 KB
testcase_10 AC 358 ms
75,008 KB
testcase_11 AC 375 ms
76,604 KB
testcase_12 AC 372 ms
77,464 KB
testcase_13 AC 373 ms
76,628 KB
testcase_14 AC 369 ms
75,744 KB
testcase_15 AC 361 ms
76,956 KB
testcase_16 AC 367 ms
73,720 KB
testcase_17 AC 360 ms
75,820 KB
testcase_18 AC 356 ms
76,760 KB
testcase_19 AC 366 ms
76,408 KB
testcase_20 AC 360 ms
76,820 KB
testcase_21 AC 358 ms
76,088 KB
testcase_22 AC 360 ms
76,392 KB
testcase_23 AC 359 ms
75,820 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package adv2017;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class N624_4 {
	static Scanner in;
	static PrintWriter out;
	static String INPUT = "";
	
	static boolean DEBUG = false;
	static Random ugen = new Random(1);
	static int[] ANS = shuffle(100, ugen);
	
	static void solve()
	{
		int Q = ni();
		Random gen = new Random();
		int[] ord = shuffle(100, gen);
		
		tens = new int[100];
		Arrays.fill(tens, -1);
		ones = new int[100];
		Arrays.fill(ones, -1);
		
		{
			int[] alive = Arrays.copyOf(ord, 100);
			for(int i = 0;i < 9;i++){
				tr(i);
				dfs(alive, 0, alive.length, i, 10);
				if(i <= 7){
					int[] nalive = new int[90-i*10];
					int p = 0;
					for(int j = 0;j < alive.length;j++){
						if(tens[alive[j]] == -1){
							nalive[p++] = alive[j];
						}
					}
					assert nalive.length == p;
					alive = nalive;
				}else{
					for(int j = 0;j < alive.length;j++){
						if(tens[alive[j]] == -1){
							tens[alive[j]] = 9;
						}
					}
				}
			}
		}
		{
			int[] alive = Arrays.copyOf(ord, 100);
			for(int i = 0;i < 9;i++){
				dfs1(alive, 0, alive.length, i, 10);
				if(i <= 7){
					int[] nalive = new int[90-i*10];
					int p = 0;
					for(int j = 0;j < alive.length;j++){
						if(ones[alive[j]] == -1){
							nalive[p++] = alive[j];
						}
					}
					assert nalive.length == p;
					alive = nalive;
				}else{
					for(int j = 0;j < alive.length;j++){
						if(ones[alive[j]] == -1){
							ones[alive[j]] = 9;
						}
					}
				}
			}
		}
		String[] ans = new String[100];
		for(int i = 0;i < 100;i++){
			ans[i] = "" + tens[i] + ones[i];
		}
		q(ans, true);
	}
	
	static int[] q(String[] qs, boolean end)
	{
		if(DEBUG){
			int[] ret = new int[3];
			for(int i = 0;i < 100;i++){
				String t = Integer.toString(100 + ANS[i]);
				int hit = 0;
				for(int j = 0;j < 2;j++){
					if(t.charAt(1+j) == qs[i].charAt(j)){
						hit++;
					}
				}
				ret[hit]++;
			}
			return ret;
		}else{
			for(int i = 0;i < qs.length;i++){
				if(i > 0)out.print(" ");
				out.print(qs[i]);
			}
			out.println();
			out.flush();
			if(!end){
				return new int[]{ni(), ni(), ni()};
			}else{
				return null;
			}
		}
	}
	
//	
	static int[] tens;
	static int[] ones;
	
	static void dfs(int[] alive, int l, int r, int z, int prev)
	{
		if(prev == r-l){
			for(int i = l;i < r;i++){
				tens[alive[i]] = z;
			}
			return;
		}
//		tr(l, r, prev, r-l);
		
		int h = l+r>>1;
		String[] qs = new String[100];
		Arrays.fill(qs, "??");
		for(int i = 0;i < h-l;i++){
			qs[alive[l+i]] = z + "?";
		}
		int lc = q(qs, false)[1];
		if(lc > 0)dfs(alive, l, h, z, lc);
		if(prev-lc > 0)dfs(alive, h, r, z, prev-lc);
	}
	
	static void dfs1(int[] alive, int l, int r, int z, int prev)
	{
		if(prev == r-l){
			for(int i = l;i < r;i++){
				ones[alive[i]] = z;
			}
			return;
		}
		
		int h = l+r>>1;
		String[] qs = new String[100];
		Arrays.fill(qs, "??");
		for(int i = 0;i < h-l;i++){
			qs[alive[l+i]] = "?" + z;
		}
		int lc = q(qs, false)[1];
		if(lc > 0)dfs1(alive, l, h, z, lc);
		if(prev-lc > 0)dfs1(alive, h, r, z, prev-lc);
	}
	
	public static int[] shuffle(int n, Random gen){ int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = i; for(int i = 0;i < n;i++){ int ind = gen.nextInt(n-i)+i; int d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; }

	
	public static void main(String[] args) throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
	}
	
	static int ni() { return Integer.parseInt(in.next()); }
	static long nl() { return Long.parseLong(in.next()); }
	static double nd() { return Double.parseDouble(in.next()); }
	static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}
0