結果

問題 No.3110 Like CPCTF?
コンテスト
ユーザー Ryoga.exe
提出日時 2025-04-19 03:26:13
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 0 ms / 2,000 ms
コード長 940 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 786 ms
コンパイル使用メモリ 148,956 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2026-07-09 21:27:45
合計ジャッジ時間 2,170 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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