結果
| 問題 |
No.470 Inverse S+T Problem
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2016-12-20 11:32:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,449 bytes |
| コンパイル時間 | 606 ms |
| コンパイル使用メモリ | 49,692 KB |
| 実行使用メモリ | 7,040 KB |
| 最終ジャッジ日時 | 2024-12-22 13:28:53 |
| 合計ジャッジ時間 | 1,755 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%s",buf);
| ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
int n;
char buf[25];
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){
scanf("%s",buf);
u[i] = string(buf);
}
if(n>=53){
puts("Impossible");
return 0;
}
// cut a/bc -> true(0)
// cut ab/c -> false(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);
REP(o,2)REP(p,2){
bool ok = ((o==0?a:c)!=(p==0?x:z)) && ((o==0?b+c:a+b)!=(p==0?y+z:x+y));
if(!ok)g[2*i+o][2*j+p^1] = g[2*j+p][2*i+o^1] = true;
}
}
bool flag = true;
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,n)if(g[2*i][2*i+1] && g[2*i+1][2*i])flag = false;
if(!flag){
puts("Impossible");
}else{
REP(i,n)used[i] = -1;
REP(i,n)if(used[i]==-1)dfs(i,g[2*i][2*i+1]);
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