結果

問題 No.282 おもりと天秤(2)
ユーザー GrenacheGrenache
提出日時 2015-09-19 00:54:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,838 bytes
コンパイル時間 5,602 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 68,472 KB
平均クエリ数 3.92
最終ジャッジ日時 2023-09-23 06:15:14
合計ジャッジ時間 12,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
65,104 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 69 ms
63,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder282 {

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

        int n = sc.nextInt();

        int[] lr = new int[2 * n];
        for (int i = 0; i < n; i++) {
        	lr[i] = i + 1;
        }

        for (int i = 0; i < n * n; i++) {
        	if (ask(lr, i % 2)) {
        		ask(lr, 0);
        		break;
        	}
        }

    	StringBuilder s = new StringBuilder();
    	s.append("! ");
    	for (int i = 0; i < n; i++) {
    		if (i != 0) {
    			s.append(' ');
    		}
    		s.append(lr[i]);
    	}
    	
    	pr.println(s);
    	pr.flush();

    	pr.close();
        sc.close();
    }
    
    static boolean ask(int[] lr, int flag) {
    	int n = lr.length;
    	if (flag == 1) {
    		int tmp = lr[0];
    		lr[0] = lr[n - 1];
    		lr[n - 1] = tmp;
    	}
    	StringBuilder s = new StringBuilder();
    	s.append("? ");
    	for (int i = 0; i < n; i++) {
    		if (i != 0) {
    			s.append(' ');
    		}
    		s.append(lr[i]);
    	}
    	
    	pr.println(s);
    	pr.flush();

    	if (flag == 1) {
    		int tmp = lr[0];
    		lr[0] = lr[n - 1];
    		lr[n - 1] = tmp;
    	}

    	boolean ret = true;
    	for (int i = 0; i < n / 2; i++) {
    		char ans = sc.next().charAt(0);
    		if (i < n - 1 && lr[i * 2 + 1] != 0 && ans == '>') {
    			int tmp = lr[i * 2];
    			lr[i * 2] = lr[i * 2 + 1];
    			lr[i * 2 + 1] = tmp;
    			
    			ret = false;
    		}
    	}
    	
    	return ret;
    }
    
    static Scanner sc;
    static Printer pr;
    
	@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