結果

問題 No.562 超高速一人かるた small
ユーザー PachicobuePachicobue
提出日時 2017-08-26 18:14:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 844 ms / 3,000 ms
コード長 2,432 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 176,036 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 17:14:37
合計ジャッジ時間 12,267 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 AC 81 ms
6,940 KB
testcase_09 AC 822 ms
6,944 KB
testcase_10 AC 172 ms
6,940 KB
testcase_11 AC 375 ms
6,940 KB
testcase_12 AC 80 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 829 ms
6,940 KB
testcase_15 AC 834 ms
6,940 KB
testcase_16 AC 837 ms
6,944 KB
testcase_17 AC 815 ms
6,940 KB
testcase_18 AC 844 ms
6,944 KB
testcase_19 AC 834 ms
6,940 KB
testcase_20 AC 840 ms
6,944 KB
testcase_21 AC 827 ms
6,944 KB
testcase_22 AC 828 ms
6,940 KB
testcase_23 AC 834 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

struct Graph {
    Graph(const ll n)
    {
        edge.resize(n, vector<ll>(n));
    }
    void addEdge(const ll from, const ll to, const ll cost)
    {
        edge[from][to] = cost;
        edge[to][from] = cost;
    }
    vector<vector<ll>> edge;
};

inline ll common(const string& s1, const string& s2)
{
    ll c = 0;
    for (ll i = 0; i < min(s1.size(), s2.size()); i++) {
        if (s1[i] == s2[i]) {
            c++;
        } else {
            break;
        }
    }
    return c + 1;
}

ll frac(const ll n)
{
    ll ans = 1;
    for (ll i = 1; i <= n; i++) {
        ans = (ans * i) % MOD;
    }
    return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;
    const ll maximum = 1 << N;
    vector<string> S(N);
    Graph g(N);
    for (ll i = 0; i < N; i++) {
        cin >> S[i];
    }
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            g.addEdge(i, j, common(S[i], S[j]));
        }
    }

    vector<ll> costs(N);
    for (ll i = 1; i < maximum; i++) {
        vector<bool> used(N, false);
        ll num = i;
        ll cost = 0;
        ll pop = 0;
        for (ll d = 0; d < N; d++) {
            if (num % 2 == 1) {
                pop++;
                ll maxi = 1;
                for (ll j = 0; j < N; j++) {
                    if (not used[j]) {
                        maxi = max(maxi, g.edge[d][j]);
                    }
                }
                cost = (cost + maxi) % MOD;
                used[d] = true;
            }
            num /= 2;
        }
        costs[pop - 1] = (costs[pop - 1] + cost) % MOD;
    }
    for (int i = 0; i < N; i++) {
        cout << (frac(i + 1) * costs[i]) % MOD << endl;
    }


    return 0;
}
0