結果

問題 No.282 おもりと天秤(2)
ユーザー koyumeishikoyumeishi
提出日時 2015-09-19 00:03:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,048 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 93,904 KB
実行使用メモリ 31,476 KB
平均クエリ数 818.04
最終ジャッジ日時 2023-09-23 06:05:29
合計ジャッジ時間 8,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#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]]++;
			}
		}
	}

	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