結果
問題 | No.282 おもりと天秤(2) |
ユーザー | ぴろず |
提出日時 | 2015-09-18 23:49:00 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 3,222 ms / 5,000 ms |
コード長 | 1,780 bytes |
コンパイル時間 | 3,527 ms |
コンパイル使用メモリ | 90,900 KB |
実行使用メモリ | 94,200 KB |
平均クエリ数 | 267.12 |
最終ジャッジ日時 | 2024-07-16 21:23:46 |
合計ジャッジ時間 | 37,769 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
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()); } }