結果

問題 No.470 Inverse S+T Problem
ユーザー koba-e964koba-e964
提出日時 2016-12-20 16:34:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,865 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 117,968 KB
実行使用メモリ 6,264 KB
最終ジャッジ日時 2023-08-24 01:21:49
合計ジャッジ時間 2,964 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 18 ms
6,176 KB
testcase_07 AC 18 ms
6,264 KB
testcase_08 AC 18 ms
6,144 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  cin >> n;
  vector<string> u(n);
  REP(i, 0, n) {
    cin >> u[i];
  }
  {
    set<char> res;
    REP(i, 0, n) {
      res.insert(u[i][0]);
      res.insert(u[i][2]);
      if (res.size() < i + 1) {
	cout << "Impossible" << endl;
	return 0;
      }
    }
  }
  assert (n <= 52);
  vector<int> used(n);
  vector<pair<pair<char, string>, int> > pool;
  REP(i, 0, n) {
    pool.push_back(make_pair(make_pair(u[i][0], u[i].substr(1, 2)), i));
    pool.push_back(make_pair(make_pair(u[i][2], u[i].substr(0, 2)), n + i));
  }
  sort(pool.begin(), pool.end());
  set<char> p1;
  set<string> p2;
  int uc = 0;
  REP(i, 0, pool.size()) {
    int idx = pool[i].second % n;
    char cc = pool[i].first.first;
    string cd = pool[i].first.second;
    if (used[idx] == 0 && p1.count(cc) == 0 && p2.count(cd) == 0) {
      p1.insert(cc);
      p2.insert(cd);
      uc++;
      used[idx] = pool[i].second >= n ? 2 : 1;
    }
  }
  assert (uc <= n);
  if (uc < n) {
    cout << "Impossible" << endl;
    return 0;
  }
  REP(i, 0, n) {
    if (used[i] == 1) {
      cout << u[i][0] << " " <<  u[i].substr(1, 2) << endl;
    } else {
      assert (used[i] == 2);
      cout << u[i].substr(0, 2) << " " << u[i][2] << endl;
    }
  }
}
0