結果
| 問題 |
No.470 Inverse S+T Problem
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2016-12-20 11:20:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,324 bytes |
| コンパイル時間 | 1,515 ms |
| コンパイル使用メモリ | 164,764 KB |
| 実行使用メモリ | 7,700 KB |
| 最終ジャッジ日時 | 2024-12-22 13:28:38 |
| 合計ジャッジ時間 | 2,920 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
int n;
string u[125252];
string s[53],t[53];
bool g[125][125];
int used[53];
void dfs(int p,int v){
used[p] = v;
int from = 2*p+v;
REP(to,2*n){
if(!g[from][to])continue;
if(used[to/2]!=-1)continue;
dfs(to/2,to%2);
}
}
int main(){
scanf("%d",&n);
REP(i,n)cin>>u[i];
if(n>=53){
puts("Impossible");
return 0;
}
// cut a/bc -> true
// cut ab/c -> false
bool flag = true;
REP(i,n)used[i] = -1;
REP(i,n)REP(j,i){
string a = u[i].substr(0,1);
string b = u[i].substr(1,1);
string c = u[i].substr(2,1);
string x = u[j].substr(0,1);
string y = u[j].substr(1,1);
string z = u[j].substr(2,1);
bool tt = (a!=x)&&(b+c!=y+z);
bool tf = (a!=z)&&(b+c!=x+y);
bool ft = (a+b!=y+z)&&(c!=x);
bool ff = (a+b!=x+y)&&(c!=z);
// printf("%d %d -> %d %d %d %d\n",i,j,tt,tf,ft,ff);
if(!tt){
g[2*i][2*j+1] = true;
g[2*j][2*i+1] = true;
}
if(!tf){
g[2*i][2*j] = true;
g[2*j+1][2*i+1] = true;
}
if(!ft){
g[2*i+1][2*j+1] = true;
g[2*j][2*i] = true;
}
if(!ff){
g[2*i+1][2*j] = true;
g[2*j+1][2*i] = true;
}
}
// REP(i,2*n){
// REP(j,2*n)printf("%2d",g[i][j]);
// puts("");
// }puts("");
REP(k,2*n)REP(i,2*n)REP(j,2*n)g[i][j]=g[i][j]||(g[i][k]&&g[k][j]);
// REP(i,2*n){
// REP(j,2*n)printf("%2d",g[i][j]);
// puts("");
// }
REP(i,n)if(g[2*i][2*i+1] && g[2*i+1][2*i])flag = false;
if(!flag){
puts("Impossible");
}else{
REP(i,n)if(used[i]==-1)dfs(i,0);
REP(i,n){
if(used[i]==0){
printf("%s %s\n",u[i].substr(0,1).c_str(), u[i].substr(1,2).c_str());
}else{
printf("%s %s\n",u[i].substr(0,2).c_str(), u[i].substr(2,1).c_str());
}
}
}
return 0;
}
rickytheta