結果

問題 No.3714 Prefix Team Name
コンテスト
ユーザー t98slider
提出日時 2026-09-18 22:53:04
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 66 ms / 2,000 ms
+ 328µs
コード長 3,870 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,685 ms
コンパイル使用メモリ 363,148 KB
実行使用メモリ 11,896 KB
最終ジャッジ日時 2026-09-18 22:53:11
合計ジャッジ時間 5,326 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

unsigned long long xor64() {
    static unsigned long long x
        = (unsigned long long)(chrono::duration_cast<chrono::nanoseconds>(
            chrono::high_resolution_clock::now().time_since_epoch()).count())
            * 10150724397891781847ULL;
    x ^= x << 7;
    return x ^= x >> 9;
}

template<const long long MOD = 2305843009213693951, 
        const long long MASK31 = (1ll << 31) - 1, const long long MASK30 = (1ll << 30) - 1>
struct modint61 {
    using mint = modint61;
    long long v;
    modint61() : v(0) {}
    template<class T> modint61(T x) { 
        while(x < 0) x += MOD;
        while(x >= MOD) x -= MOD;
        v = x;
    }
    long long safe_mod(long long x){
        x = (x >> 61) + (x & MOD);
        if (x >= MOD) x -= MOD;
        return x;
    }
    static constexpr long long mod() { return MOD; }
    mint& operator++() {v++; if(v == MOD)v = 0; return *this;}
    mint& operator--() {if(v == 0)v = MOD; v--; return *this;}
    mint operator++(int) { mint result = *this; ++*this; return result; }
    mint operator--(int) { mint result = *this; --*this; return result; }
    mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; }
    mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; }
    mint& operator*=(const mint& rhs) {
        long long u = v >> 31, d = v & MASK31;
        long long ru = rhs.v >> 31, rd = rhs.v & MASK31;
        long long mid = d * ru + u * rd;
        v = safe_mod(u * ru * 2 + (mid >> 30) + ((mid & MASK30) << 31) + d * rd);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint r = 1, x = *this;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { assert(v); return pow(MOD - 2); }
    friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; }
    friend bool operator<(const mint& lhs, const mint& rhs) { return lhs.v < rhs.v; }
    friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); }
    friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); }
    friend std::istream& operator >> (std::istream& is, mint& rhs) noexcept {
        long long tmp;
        rhs = mint{(is >> tmp, tmp)};
        return is;
    }
    friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; }
};
using mint61 = modint61<2305843009213693951>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<string> a(3);
    cin >> a[0] >> a[1] >> a[2];
    vector<mint61> S;
    mint61 base = xor64(), A = 0, B = 0, C = 0;
    sort(a.begin(), a.end());
    do{
        A = 0;
        for(int i = 0; i < a[0].size(); i++){
            A *= base;
            A += a[0][i];
            B = A;
            for(int j = 0; j < a[1].size(); j++){
                B *= base;
                B += a[1][j];
                C = B;
                for(int k = 0; k < a[2].size(); k++){
                    C *= base;
                    C += a[2][k];
                    S.emplace_back(C);
                }
            }
        }
    }while(next_permutation(a.begin(), a.end()));
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << '\n';
}
0