結果
問題 | No.470 Inverse S+T Problem |
ユーザー |
![]() |
提出日時 | 2016-12-20 09:54:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,483 bytes |
コンパイル時間 | 1,701 ms |
コンパイル使用メモリ | 162,536 KB |
実行使用メモリ | 8,516 KB |
最終ジャッジ日時 | 2024-12-22 13:27:42 |
合計ジャッジ時間 | 3,211 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 WA * 9 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; string S[101010]; int R[101010][4]; int A[101010]; int SS[5050]; void dfs(int d) { if(d==N) { int i; FOR(i,N) { if(A[i]==0) cout<<S[i].substr(0,1)<<" "<<S[i].substr(1,2)<<endl; else cout<<S[i].substr(0,2)<<" "<<S[i].substr(2,1)<<endl; } exit(0); } if(SS[R[d][0]]==0 && SS[R[d][1]]==0) { A[d]=0; SS[R[d][0]]=SS[R[d][1]]=1; dfs(d+1); SS[R[d][0]]=SS[R[d][1]]=0; } if(R[d][3]!=R[d][1] && SS[R[d][2]]==0 && SS[R[d][3]]==0) { A[d]=1; SS[R[d][2]]=SS[R[d][3]]=1; dfs(d+1); SS[R[d][2]]=SS[R[d][3]]=1; } } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; if(N>52) return _P("Impossible\n"); FOR(i,N) { cin>>S[i]; R[i][0]=S[i][0]; R[i][1]=256+S[i][1]*(int)256+S[i][2]; R[i][2]=S[i][2]; R[i][3]=256+S[i][0]*(int)256+S[i][1]; } dfs(0); _P("Impossible\n"); } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }