結果
問題 |
No.470 Inverse S+T Problem
|
ユーザー |
|
提出日時 | 2016-12-20 01:24:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,990 bytes |
コンパイル時間 | 1,952 ms |
コンパイル使用メモリ | 181,820 KB |
実行使用メモリ | 13,640 KB |
最終ジャッジ日時 | 2024-12-22 13:15:50 |
合計ジャッジ時間 | 42,066 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 TLE * 13 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<<endl #define smax(x,y) (x)=max((x),(y)) #define smin(x,y) (x)=min((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; const string ALPHA="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int N; string U[100001]; map<string, int> ms; set<string> us; int def[52]; string x[52], y[52]; void ng() { cout << "Impossible" << endl; exit(0); } void f(int cu) { if(cu == 52) { if(sz(us) == 2 * N) { rep(i, N)cout << x[i] << ' ' << y[i] << endl; exit(0); } else { return; } } int non = 1; char c = ALPHA[cu]; rep(i, N) if(!def[i]){ string &u = U[i]; def[i] = 1; if(u[0] == c) { non = 0; x[i] = u.substr(0, 1); y[i] = u.substr(1, 2); if(us.count(y[i]) + us.count(x[i]) == 0) { us.insert(x[i]); us.insert(y[i]); f(cu + 1); us.erase(x[i]); us.erase(y[i]); } } if(u[2] == c) { non = 0; x[i] = u.substr(0, 2); y[i] = u.substr(2, 1); if(us.count(x[i]) + us.count(y[i]) == 0) { us.insert(x[i]); us.insert(y[i]); f(cu + 1); us.erase(x[i]); us.erase(y[i]); } } def[i] = 0; } f(cu + 1); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> N; rep(i, N)cin >> U[i]; if(N > 52) { ng(); } f(0); ng(); }