結果
| 問題 |
No.470 Inverse S+T Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-21 01:36:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,112 bytes |
| コンパイル時間 | 4,728 ms |
| コンパイル使用メモリ | 261,100 KB |
| 最終ジャッジ日時 | 2025-01-29 12:29:24 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 9 |
ソースコード
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
bool chmax(ll& p, ll q) {
if (p < q) {
p = q;
return 1;
}
else {
return 0;
}
}
bool chmin(ll& p, ll q) {
if (p > q) {
p = q;
return 1;
}
else {
return 0;
}
}
ll PM(ll P, ll Q) {
if (Q == 0)return P * 10;
ll k = 1;
ll V = Q;
while (V > 0) {
V /= 10;
k *= 10;
}
return P * k + Q;
}
int main() {
ll N;
cin >> N;
if (N > 26) {
cout << "Impossible" << endl;
return 0;
}
vector<string> S(N);
rep(i, N)cin >> S[i];
two_sat ts(N);
rep(i, N)rep(j, i) {
if (S[i].substr(0, 1) == S[j].substr(0, 1)) {
ts.add_clause(i, 1, j, 1);
}
if (S[i].substr(0, 1) == S[j].substr(2, 1)) {
ts.add_clause(i, 1, j, 0);
}
if (S[i].substr(2, 1) == S[j].substr(0, 1)) {
ts.add_clause(i, 0, j, 1);
}
if (S[i].substr(2, 1) == S[j].substr(2, 1)) {
ts.add_clause(i,0, j, 0);
}
if (S[i].substr(1, 2) == S[j].substr(1, 2)) {
ts.add_clause(i, 1, j, 1);
}
if (S[i].substr(1, 2) == S[j].substr(0, 2)) {
ts.add_clause(i, 1, j, 0);
}
if (S[i].substr(0, 2) == S[j].substr(1, 2)) {
ts.add_clause(i, 0, j, 1);
}
if (S[i].substr(0, 2) == S[j].substr(0, 2)) {
ts.add_clause(i, 0, j, 0);
}
}
bool C = ts.satisfiable();
if(!C)cout<< "Impossible" << endl;
else {
auto v = ts.answer();
rep(i, N) {
if (v[i]) {
cout << S[i].substr(0, 2) << " " << S[i].substr(2, 1) << endl;
}
else {
cout << S[i].substr(0, 1) << " " << S[i].substr(1,2) << endl;
}
}
}
}