結果

問題 No.282 おもりと天秤(2)
ユーザー ぴろずぴろず
提出日時 2015-09-18 23:49:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 2,583 ms / 5,000 ms
コード長 1,780 bytes
コンパイル時間 3,839 ms
コンパイル使用メモリ 89,980 KB
実行使用メモリ 90,932 KB
平均クエリ数 267.12
最終ジャッジ日時 2023-09-23 21:33:56
合計ジャッジ時間 32,800 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
72,356 KB
testcase_01 AC 269 ms
75,036 KB
testcase_02 AC 223 ms
73,472 KB
testcase_03 AC 217 ms
73,052 KB
testcase_04 AC 212 ms
72,348 KB
testcase_05 AC 262 ms
74,848 KB
testcase_06 AC 274 ms
76,064 KB
testcase_07 AC 220 ms
72,820 KB
testcase_08 AC 271 ms
75,936 KB
testcase_09 AC 175 ms
73,060 KB
testcase_10 AC 727 ms
78,624 KB
testcase_11 AC 2,443 ms
89,376 KB
testcase_12 AC 1,442 ms
85,648 KB
testcase_13 AC 1,497 ms
90,560 KB
testcase_14 AC 1,956 ms
89,068 KB
testcase_15 AC 2,377 ms
89,680 KB
testcase_16 AC 415 ms
77,160 KB
testcase_17 AC 1,503 ms
87,940 KB
testcase_18 AC 1,908 ms
90,224 KB
testcase_19 AC 2,011 ms
89,792 KB
testcase_20 AC 2,552 ms
88,024 KB
testcase_21 AC 2,578 ms
87,992 KB
testcase_22 AC 2,583 ms
90,932 KB
testcase_23 AC 149 ms
71,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no282;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	static int[][] compare;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		compare = new int[n][n];
		Queue<Integer> check = new ArrayDeque<>();
		for(int i=1;i<=n;i++) {
			for(int j=i+1;j<=n;j++) {
				check.add(i * 1000 + j);
			}
		}
		while(!check.isEmpty()) {
			ArrayList<Integer> query = new ArrayList<>();
			boolean[] used = new boolean[n];
			int s = check.size();
			int checked = 0;
			while(checked < s && query.size() < n) {
				checked++;
				int x = check.poll();
				int a = x / 1000 - 1;
				int b = x % 1000 - 1;
				if (used[a] || used[b]) {
					check.offer(x);
					continue;
				}
				query.add(x);
				used[a] = used[b] = true;
			}
			while(query.size() < n) {
				query.add(0);
			}
			StringBuilder sb = new StringBuilder();
			sb.append('?');
			for(int i=0;i<n;i++) {
				sb.append(" " + query.get(i) / 1000 + " " + query.get(i) % 1000);
			}
			System.out.println(sb.toString());
			for(int i=0;i<n;i++) {
				int a = query.get(i) / 1000 - 1;
				int b = query.get(i) % 1000 - 1;
				char c = sc.next().charAt(0);
				if (a < 0) {
					continue;
				}
				compare[a][b] = c == '<' ? -1 : c == '>' ? 1 : 0;
				compare[b][a] = -compare[a][b];
 			}
		}

//		System.out.println(Arrays.deepToString(compare));

		Integer[] ans = new Integer[n];
		for (int i = 0; i < n; i++) {
			ans[i] = i;
		}
		Arrays.sort(ans, (x, y) -> compare[x][y]);
		StringBuilder sb = new StringBuilder();
		sb.append('!');
		for (int i = 0; i < n; i++) {
			sb.append(' ');
			sb.append(ans[i] + 1);
		}
		System.out.println(sb.toString());
	}

}
0