結果

問題 No.282 おもりと天秤(2)
ユーザー koyumeishikoyumeishi
提出日時 2015-09-19 00:06:32
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,084 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 92,304 KB
実行使用メモリ 31,460 KB
平均クエリ数 817.08
最終ジャッジ日時 2023-09-23 06:07:55
合計ジャッジ時間 11,706 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cassert>
#include <set>
using namespace std;

//dfs
//O(V+E)
void TopologicalSort(vector<vector<int> > &G, vector<int> &res, int node, vector<bool> &visit){
	if(visit[node] == true) return;
	visit[node] = true;
	for(auto itr = G[node].rbegin(); itr != G[node].rend(); itr++){
		TopologicalSort(G, res, *itr, visit);
	}
	/*
	for(int i=0; i<G[node].size(); i++){
		TopologicalSort(G, res, G[node][i], visit);
	}
	*/
	res.push_back(node);
}


int main(){
	int n;
	cin >> n;

	vector<set<int>> E(n);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) continue;
			E[i].insert(j);
		}
	}

	vector<vector<int>> G(n);
	vector<int> in_edge(n, 0);

	for(;;){
		string out = "?";
		vector<int> v;
		vector<bool> used(2*n, false);
		bool update = false;
		for(int j=0; j<n; j++){
			if(used[j]) continue;
			if(E[j].size() == 0) continue;
			int x = j;
			auto itr = E[j].begin();
			while(itr != E[j].end() && used[*itr]){
				itr++;
			}
			if(itr == E[j].end()) break;
			int y = *itr;

			used[x] = true;
			used[y] = true;
			E[x].erase(y);
			E[y].erase(x);
			v.push_back(x);
			v.push_back(y);

			update = true;
		}

		if(update == false) break;

		v.resize(2*n, -1);
		for(int j:v){
			out += " ";
			out += j+1 + '0';
		}

		cout << out << endl;

		for(int j=0; j<n; j++){
			string in;
			cin >> in;
			if(v[2*j] == -1 || v[2*j+1] == -1) continue;
			if(in == "=") continue;
			if(in == "<"){
				G[v[2*j]].push_back(v[2*j+1]);
				in_edge[v[2*j+1]]++;
			}
			if(in == ">"){
				G[v[2*j+1]].push_back(v[2*j]);
				in_edge[v[2*j]]++;
			}
		}
	}

	assert(false);

	vector<int> res;
	vector<bool> visit(n, false);

	int start = -1;

	for(int i=0; i<n; i++){
		if(in_edge[i] == 0){
			start = i;
			break;
		}
	}

	TopologicalSort(G, res, start, visit);
	reverse(res.begin(), res.end());

	string out = "!";
	for(int i : res){
		out += " ";
		out += i+1 + '0';
	}

	cout << out << endl;

	return 0;
}
0