結果

問題 No.470 Inverse S+T Problem
コンテスト
ユーザー vjudge1
提出日時 2026-06-19 10:23:00
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,336 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,831 ms
コンパイル使用メモリ 202,476 KB
実行使用メモリ 11,820 KB
最終ジャッジ日時 2026-06-19 10:23:05
合計ジャッジ時間 3,773 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 19 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
string ans[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<string, int>> vec;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        vec.push_back({s, i});
    }
    sort(vec.begin(), vec.end(), [](const auto& a, const auto& b) {
        return a.first[1] > b.first[1];
    });
    set<string> used;
    bool impossible = false;
    for (auto& p : vec) {
        string s = p.first;
        string s1 = s.substr(0, 1);
        string s2 = s.substr(1, 2);
        if (used.find(s1) == used.end() && used.find(s2) == used.end()) {
            used.insert(s1);
            used.insert(s2);
            ans[p.second] = s1 + " " + s2;
        } else {
            s1 = s.substr(0, 2);
            s2 = s.substr(2, 1);
            if (used.find(s1) == used.end() && used.find(s2) == used.end()) {
                used.insert(s1);
                used.insert(s2);
                ans[p.second] = s1 + " " + s2;
            } else {
                impossible = true;
                break;
            }
        }
    }
    if (impossible) {
        cout << "Impossible\n";
    } else {
        for (int i = 0; i < n; i++) {
            cout << ans[i] << '\n';
        }
    }
    return 0;
}
0