結果

問題 No.548 国士無双
ユーザー @abcde@abcde
提出日時 2019-02-24 11:51:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 165,508 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 17:33:40
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    
    // 1. 入力情報取得.
    string S;
    cin >> S;
    
    // 2. Sに1文字加えて, 問題文の条件を満たすように出来るか?
    string str = "abcdefghijklm";
    // 2-1. 問題文の条件を満たす文字列の配列を作成.
    string judgment[13];
    for(int i = 0; i < 13; i++){
        judgment[i] = str + str[i];
        sort(judgment[i].begin(), judgment[i].end());
    }
    
    // 2-2. 入力文字列 S に 1文字加えて, 2-1. の 配列 と 照合.
    int counter = 0;
    for(int i = 0; i < 13; i++){
        char c = str[i];
        
        // 2-1. 入力文字列 S に 1文字加え, 昇順sort.
        string X = S + c;
        sort(X.begin(), X.end());
        
        // 2-2. 比較対象文字列 の 配列 と 照合.
        for(int j = 0; j < 13; j++){
            // 文字列X, Y を比較し, 等しければ, 追加した文字(c)を出力.
            if(X == judgment[j]){
                cout << c << endl;
                // cout << "X=" << X << " judgment=" << judgment[j] << " c=" << c << endl;
                // ex.
                // [入力値]
                // abcdfghijklmm
                // -> X=abcdefghijklmm judgment=abcdefghijklmm c=e のように照合される.
                counter++;
                break;
            }
        }
    }
    
    // 3. 終了.
    // if(counter == 0) cout << -1 << endl;
    // -> Sample_2.txt 等 の WAになったので修正.
    if(counter == 0) cout << "Impossible" << endl;
    return 0;
    
}
0