結果

問題 No.470 Inverse S+T Problem
ユーザー autumn-eelautumn-eel
提出日時 2017-12-28 20:20:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,373 bytes
コンパイル時間 3,011 ms
コンパイル使用メモリ 180,664 KB
実行使用メモリ 11,076 KB
最終ジャッジ日時 2023-08-24 01:31:36
合計ジャッジ時間 6,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,076 KB
testcase_01 AC 4 ms
6,604 KB
testcase_02 AC 4 ms
6,652 KB
testcase_03 AC 4 ms
6,528 KB
testcase_04 AC 4 ms
6,656 KB
testcase_05 AC 4 ms
6,584 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

class Scc{
	vector<int>vs;
	vector<bool>used;
	vector<vector<int>>E,G;
public:
	vector<int>cmp;
	int n;
	Scc(int N){
		n=N;
		E.resize(n);
		G.resize(n);
		cmp.resize(n);
	}
private:
	void dfs(int v){
		used[v]=true;
		for(auto u:E[v]){
			if(!used[u])dfs(u);
		}
		vs.push_back(v);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		for(auto u:G[v]){
			if(!used[u])rdfs(u,k);
		}
	}
public:
	void add_edge(int a,int b){
		E[a].push_back(b);
		G[b].push_back(a);
	}
	int scc(){
		used.assign(n,0);
		vs.clear();
		for(int v=0;v<n;v++){
			if(!used[v])dfs(v);
		}
		used.assign(n,0);
		int k=0;
		for(int i=vs.size()-1;i>=0;i--){
			if(!used[vs[i]])rdfs(vs[i],k++);
		}
		return k;
	}
};
string u[100000];
int main(){
	int n;scanf("%d",&n);
	rep(i,n)cin>>u[i];
	Scc scc(n*2);
	rep(i,n)for(int j=i+1;j<n;j++)rep(k,2)rep(t,2){
		string S=u[i].substr(k,2),T=u[j].substr(t,2);
		string S2;S2+=u[i][(!k)*2];
		string T2;T2+=u[j][(!t)*2];
		if(S==T||S2==T2){
			scc.add_edge(i+k*n,j+(!t)*n);
			scc.add_edge(j+t*n,i+(!k)*n);
		}
	}
	scc.scc();
	rep(i,n){
		if(scc.cmp[i]==scc.cmp[i+n]){
			puts("Impossible");
			return 0;
		}
	}
	rep(i,n){
		if(scc.cmp[i]>scc.cmp[i+n]){
			cout<<u[i].substr(0,2)<<' '<<u[i][2]<<endl;
		}
		else{
			cout<<u[i][0]<<' '<<u[i].substr(1,2)<<endl;
		}
	}
}
0