結果

問題 No.470 Inverse S+T Problem
コンテスト
ユーザー paruki
提出日時 2016-12-20 12:11:20
言語 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,865 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,683 ms
コンパイル使用メモリ 204,808 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2026-05-28 19:35:59
合計ジャッジ時間 4,849 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 19 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:57:32: warning: ignoring return value of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::substr(size_type, size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   57 |                     U[i].substr(0, 1 + y), v = U[i].substr(1 + y, 2 - y);
      |                     ~~~~~~~~~~~^~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:56,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bitset:54,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/basic_string.h:3441:7: note: declared here
 3441 |       substr(size_type __pos = 0, size_type __n = npos) const
      |       ^~~~~~

ソースコード

diff #
raw source code

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const string ALPHA="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int N;
string U[100001];
map<string, int> ms;
set<string> us;
int x[52];

void ng() {
    cout << "Impossible" << endl;
    exit(0);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    if(N > 52) ng();
    rep(i, N)cin >> U[i];

    rep(i, N) {
        ms[U[i].substr(0, 1)]++;
        ms[U[i].substr(1, 2)]++;
    }

    rep(hoge, 10000) {
        rep(i, N) {
            string s, t;
            s = U[i].substr(0, 1+x[i]), t = U[i].substr(1+x[i], 2-x[i]);
            int y = !x[i];
            string u = U[i].substr(0, 1 + y), v = U[i].substr(1 + y, 2 - y);
            if(ms[s] > 1 || ms[t] > 1) {
                ms[s]--; ms[t]--;
                if(!ms[u] && !ms[v])x[i] = y, ms[u]++, ms[v]++;
                else ms[s]++, ms[t]++;
            } else if(ms[s] == 1 && ms[t] == 1) {
                ms[s]--; ms[t]--;
                if(ms[u] == 0 && ms[v] == 0) {
                    y = rand() % 2;
                    U[i].substr(0, 1 + y), v = U[i].substr(1 + y, 2 - y);
                    ms[u]++; ms[v]++;
                } else ms[s]++, ms[t]++;
            }
        }
    }

    each(p, ms)if(p.second > 1)ng();

    rep(i, N)cout << U[i].substr(0, 1 + x[i]) << ' ' << U[i].substr(1 + x[i], 2 - x[i]) << endl;
}
0