結果

問題 No.470 Inverse S+T Problem
ユーザー 👑 kmjpkmjp
提出日時 2016-12-20 09:51:50
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,543 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 154,352 KB
実行使用メモリ 12,808 KB
最終ジャッジ日時 2023-08-24 01:14:45
合計ジャッジ時間 5,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,808 KB
testcase_01 AC 3 ms
6,508 KB
testcase_02 AC 3 ms
6,492 KB
testcase_03 AC 3 ms
6,544 KB
testcase_04 AC 3 ms
6,504 KB
testcase_05 AC 3 ms
6,724 KB
testcase_06 AC 4 ms
6,576 KB
testcase_07 AC 3 ms
6,492 KB
testcase_08 AC 3 ms
6,568 KB
testcase_09 AC 4 ms
6,732 KB
testcase_10 AC 3 ms
6,552 KB
testcase_11 AC 87 ms
6,500 KB
testcase_12 AC 3 ms
6,492 KB
testcase_13 AC 3 ms
6,476 KB
testcase_14 AC 4 ms
6,752 KB
testcase_15 AC 8 ms
6,484 KB
testcase_16 AC 3 ms
6,592 KB
testcase_17 AC 4 ms
6,492 KB
testcase_18 AC 3 ms
6,572 KB
testcase_19 AC 11 ms
6,604 KB
testcase_20 AC 3 ms
6,488 KB
testcase_21 AC 3 ms
6,564 KB
testcase_22 AC 3 ms
6,508 KB
testcase_23 AC 3 ms
6,536 KB
testcase_24 AC 4 ms
6,648 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S[101010];
int R[101010][4];
int A[101010];
set<int> SS;

void dfs(int d) {
	if(d==N) {
		int i;
		FOR(i,N) {
			if(A[i]==0) cout<<S[i].substr(0,1)<<" "<<S[i].substr(1,2)<<endl;
			else cout<<S[i].substr(0,2)<<" "<<S[i].substr(2,1)<<endl;
		}
		exit(0);
	}
	
	if(SS.count(R[d][0])==0 && SS.count(R[d][1])==0) {
		A[d]=0;
		SS.insert(R[d][0]);
		SS.insert(R[d][1]);
		dfs(d+1);
		SS.erase(R[d][0]);
		SS.erase(R[d][1]);
		
	}
	if(SS.count(R[d][2])==0 && SS.count(R[d][3])==0) {
		A[d]=1;
		SS.insert(R[d][2]);
		SS.insert(R[d][3]);
		dfs(d+1);
		SS.erase(R[d][2]);
		SS.erase(R[d][3]);
		
	}
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	if(N>52) return _P("Impossible\n");
	FOR(i,N) {
		cin>>S[i];
		R[i][0]=S[i][0];
		R[i][1]=256+S[i][1]*(int)256+S[i][2];
		R[i][2]=S[i][2];
		R[i][3]=256+S[i][0]*(int)256+S[i][1];
	}
	
	dfs(0);
	_P("Impossible\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0