結果

問題 No.282 おもりと天秤(2)
ユーザー 37zigen37zigen
提出日時 2020-04-19 07:57:07
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,889 bytes
コンパイル時間 2,868 ms
コンパイル使用メモリ 77,568 KB
実行使用メモリ 94,636 KB
平均クエリ数 118.29
最終ジャッジ日時 2023-09-24 02:35:23
合計ジャッジ時間 15,989 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
72,868 KB
testcase_01 AC 302 ms
76,164 KB
testcase_02 AC 266 ms
75,704 KB
testcase_03 AC 241 ms
72,916 KB
testcase_04 AC 245 ms
73,208 KB
testcase_05 AC 283 ms
75,916 KB
testcase_06 AC 307 ms
76,344 KB
testcase_07 AC 231 ms
72,952 KB
testcase_08 AC 301 ms
76,080 KB
testcase_09 AC 183 ms
73,280 KB
testcase_10 AC 1,691 ms
89,012 KB
testcase_11 TLE -
testcase_12 AC 1,938 ms
90,380 KB
testcase_13 AC 3,283 ms
94,636 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void remove(boolean[][] g, int[] out_deg, boolean[] removed, int v) {
		assert(!removed[v]);
		int n=g.length;
		for (int i=0;i<n;++i) {
			if (g[i][v]) {
				--out_deg[i];
			}
		}
		removed[v]=true;
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		boolean[][] g=new boolean[N][N];
		boolean[] removed=new boolean[N];
		int[] out_deg=new int[N];
		ArrayList<Integer> ans=new ArrayList<>();
		PrintWriter pw=new PrintWriter(System.out);
		while (true) {
			ArrayList<Integer> list=new ArrayList<>();
			do {
				for (int i=0;i<N;++i) {
					if (out_deg[i]==0 && !removed[i]) {
						list.add(i);
					}
				}
				if (list.size()==1) {
					ans.add(list.get(0));
					remove(g, out_deg, removed, list.get(0));
					list.remove(0);
				} else if(list.size()==0) {
					pw.print("! ");
					for (int i=0;i<N;++i) {
						pw.print((ans.get(i)+1)+(i==N-1?"\n":" "));
					}
					pw.flush();
					return;
				}
			} while (list.size()==0);
			for (int i=0;i<N;++i) {
				if (!(out_deg[i]==0 && !removed[i])) list.add(i);
			}
			for (int i=0;i<N;++i) list.add(-1);
			pw.println("? ");
			for (int i=0;i<N;++i) {
				pw.print((list.get(2*i)+1)+" "+(list.get(2*i+1)+1)+(i==N-1?"\n":" "));
			}
			pw.flush();
			for (int i=0;i<N;++i) {
				String op=sc.next();
				int a=list.get(2*i),b=list.get(2*i+1);
				if (a!=-1 && b!=-1 && op.equals(">") && !g[a][b]) {
					g[a][b]=true;
					if (!removed[a] && !removed[b]) ++out_deg[a];
				} else if(a!=-1 && b!=-1 && op.contentEquals("<") && !g[b][a]) {
					g[b][a]=true;
					if (!removed[a] && !removed[b]) ++out_deg[b];
				}
			}
		}
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}
0