結果
| 問題 |
No.470 Inverse S+T Problem
|
| コンテスト | |
| ユーザー |
けー
|
| 提出日時 | 2017-04-15 00:59:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,287 ms / 2,000 ms |
| コード長 | 1,338 bytes |
| コンパイル時間 | 1,795 ms |
| コンパイル使用メモリ | 177,368 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-22 13:43:05 |
| 合計ジャッジ時間 | 5,010 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
char p[100000][3];
struct A{
char c[3];
bool operator<(const A &x)const{
if(c[0]<x.c[0])
return true;
else if(c[0]>x.c[0])
return false;
else
return c[1]<x.c[1];
}
A(){
c[0]=0;
c[1]=0;
c[2]=0;
}
};
ostream& operator<<(ostream &os,const A &x){
return os<<x.c;
}
set<A> se;
vector<A> ve;
int nnn;
void saiki(int u){
if(nnn>6000000){
cout<<"Impossible"<<endl;
exit(0);
}
nnn++;
if(u==a){
for(int i=0;i<a;i++)
cout<<ve[i*2]<<" "<<ve[i*2+1]<<endl;;
exit(0);
}
A s,t;
s.c[0]=p[u][0];
s.c[1]=0;
t.c[0]=p[u][1];
t.c[1]=p[u][2];
if(se.find(s)==end(se)&&se.find(t)==end(se)){
se.insert(s);
se.insert(t);
ve.push_back(s);
ve.push_back(t);
saiki(u+1);
se.erase(s);
se.erase(t);
ve.resize(ve.size()-2);
}
if(p[u][0]==p[u][1]&&p[u][1]==p[u][2])
return;
s.c[0]=p[u][0];
s.c[1]=p[u][1];
t.c[0]=p[u][2];
t.c[1]=0;
if(se.find(s)==end(se)&&se.find(t)==end(se)){
se.insert(s);
se.insert(t);
ve.push_back(s);
ve.push_back(t);
saiki(u+1);
se.erase(s);
se.erase(t);
ve.resize(ve.size()-2);
}
}
signed main(){
int i,j;
cin>>a;
for(i=0;i<a;i++)
cin>>p[i];
saiki(0);
cout<<"Impossible"<<endl;
}
けー