結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
72,504 KB
testcase_01 AC 501 ms
75,948 KB
testcase_02 AC 379 ms
76,756 KB
testcase_03 AC 326 ms
76,020 KB
testcase_04 AC 296 ms
73,104 KB
testcase_05 AC 443 ms
76,772 KB
testcase_06 AC 587 ms
75,808 KB
testcase_07 AC 291 ms
73,552 KB
testcase_08 AC 570 ms
76,952 KB
testcase_09 AC 184 ms
72,780 KB
testcase_10 AC 4,412 ms
73,300 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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<>();
		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) {
					System.out.print("! ");
					for (int i=0;i<N;++i) {
						System.out.print((ans.get(i)+1)+(i==N-1?"\n":" "));
					}
					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);
			System.out.println("? ");
			for (int i=0;i<N;++i) {
				System.out.print((list.get(2*i)+1)+" "+(list.get(2*i+1)+1)+(i==N-1?"\n":" "));
			}
			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