結果

問題 No.3110 Like CPCTF?
ユーザー Ryoga.exe
提出日時 2025-04-19 03:26:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 80,160 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-19 03:26:15
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;
    int ans = 0;
    auto rec = [&](auto self, int pos, std::string &t) -> void {
        const auto len = t.size();
        if (len == 5) {
            ans++;
            return;
        }

        for (int i = pos; i < n; i++) {
            if (len == 2) {
                if (s[i] == t[0]) {
                    t.push_back(s[i]);
                    self(self, i + 1, t);
                    t.pop_back();
                }
            } else {
                bool ng = false;
                for (const char c : t) {
                    ng |= (s[i] == c);
                }
                if (!ng) {
                    t.push_back(s[i]);
                    self(self, i + 1, t);
                    t.pop_back();
                }
            }
        }
    };
    std::string t;
    rec(rec, 0, t);
    std::cout << ans;
}
0