結果

問題 No.1112 冥界の音楽
ユーザー trineutrontrineutron
提出日時 2019-11-01 02:24:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 992 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 174,940 KB
実行使用メモリ 8,708 KB
最終ジャッジ日時 2023-10-13 00:17:10
合計ジャッジ時間 7,063 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,708 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 63 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 570 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long mod = 1000000007;

long power(long k, long n) {
    long ans = 1;
    while (n) {
        if (n % 2) {
            ans *= k;
            ans %= mod;
        }
        k *= k;
        k %= mod;
        n /= 2;
    }
    return ans;
}

int main() {
    long k, m, n, ans = 0;
    cin >> k >> m >> n;
    set<tuple<long, long, long>> s;
    for (long i = 0; i < m; i++) {
        long p, q, r;
        cin >> p >> q >> r;
        s.insert(make_tuple(p, q, r));
    }
    vector<long> t(n);
    for (long l = 0; l < power(k, n); l++) {
        long add = 1;
        for (long i = 0; i < n; i++) t.at(i) = l / power(k, i) % k + 1;
        if (t.at(0) != 1 || t.at(n - 1) != 1) continue;
        for (long i = 0; i < n - 2; i++) {
            if (s.find(make_tuple(t.at(i), t.at(i + 1), t.at(i + 2))) == s.end()) {
                add = 0;
                break;
            }
        }
        ans += add;
    }
    cout << ans << endl;
}
0