結果

問題 No.548 国士無双
ユーザー kichirb3kichirb3
提出日時 2018-03-02 22:00:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 76,544 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 17:21:32
合計ジャッジ時間 1,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// No.548 国士無双
// https://yukicoder.me/problems/no/548
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<char> solve(string &S);


int main() {
    cin.tie(nullptr);
    string S;
    cin >> S;

    vector<char> ans = solve(S);
    if (ans.empty())
        cout << "Impossible" << endl;
    else {
        for (auto a: ans)
            cout << a << endl;
    }
}


vector<char> solve(string &S) {
    vector<char> ans;
    vector<char> candidates {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'};

    for (char c: candidates) {
        string T = S + c;
        vector<int> count(13, 0);
        bool match = true;
        for (char t: T) {
            if ('a' <= t && t <= 'm')
                count[t-'a']++;
            else {
                match = false;
                break;
            }
        }
        if (*max_element(count.begin(), count.end()) > 2 || *min_element(count.begin(), count.end()) < 1)
            match = false;
        if (match)
            ans.push_back(c);
    }
    return ans;
}
0