結果

問題 No.470 Inverse S+T Problem
ユーザー chaemonchaemon
提出日時 2016-12-20 00:22:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,150 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 94,324 KB
実行使用メモリ 8,908 KB
最終ジャッジ日時 2023-08-24 01:02:15
合計ジャッジ時間 5,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 22 ms
8,484 KB
testcase_07 AC 21 ms
7,856 KB
testcase_08 AC 22 ms
8,908 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 205 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 16 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

vector<string> v;
int a[60];

int N;

set<string> ap;

bool dfs(int i=0){
	if(i==N){
		REP(j,N){
			cout<<v[j].substr(0,a[j]+1)<<" "<<v[j].substr(a[j]+1,3-(a[j]+1))<<endl;
		}
		return true;
	}
	REP(z,2){
		string s0 = v[i].substr(0,z+1), s1 = v[i].substr(z+1,3-(z+1));
		if(s0==s1 or ap.find(s0)!=ap.end() or ap.find(s1)!=ap.end())continue;
		ap.insert(s0);ap.insert(s1);
		a[i] = z;
		if(dfs(i+1))return true;
		a[i] = -1;
		ap.erase(s0);ap.erase(s1);
	}
	return false;
}

int main(){
	cin>>N;
	REP(i,N){
		string s;
		cin>>s;
		v.push_back(s);
	}
	if(N>52){
		cout<<"Impossible"<<endl;
		return 0;
	}
	memset(a,-1,sizeof(a));
	if(!dfs()){
		cout<<"Impossible"<<endl;
	}
	return 0;
}
0