結果

問題 No.140 みんなで旅行
ユーザー At-sushiAt-sushi
提出日時 2024-03-01 03:40:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 988 bytes
コンパイル時間 3,698 ms
コンパイル使用メモリ 249,304 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-01 03:40:25
合計ジャッジ時間 7,466 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

constexpr std::int64_t MOD = 1e9 + 7;

template<typename T> constexpr T pown(T a, T b) {
    const T tmp = b % 2 ? a : 1;

    return (b ? tmp * pown(a * a % MOD, b / 2) % MOD : 1);
}

template<typename T> constexpr T prod(T a, T b) {
    return (b ? a * prod(a - 1, b - 1) % MOD : 1);
}

constexpr std::int64_t mdiv(std::int64_t r) {
    return pown(r, MOD - 2) % MOD;
}

template<typename T> constexpr T coll(T a, T b) {
    return prod(a, b) * mdiv(prod(b, b)) % MOD;
}

int main() {
    std::int64_t N;

    std::cin >> N;

    std::int64_t result = 0;

    for (std::int64_t j : std::views::iota(1, N + 1)) {
        std::int64_t tmp = 0, sig = 1;
        
         for (std::int64_t i : std::views::iota(0, j + 1)) {
           tmp = (tmp + (MOD + coll(j, i) * pown(j * j - i, N) * sig) % MOD);
           sig *= -1;
         }

        result = (result + tmp * mdiv(prod(j, j))) % MOD;
    }
    
    std::cout << result << std::endl;
    
    return 0;
}
0