結果

問題 No.1050 Zero (Maximum)
ユーザー first_vilfirst_vil
提出日時 2020-05-09 17:51:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 2,131 bytes
コンパイル時間 3,695 ms
コンパイル使用メモリ 232,064 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 02:58:29
合計ジャッジ時間 4,423 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 9 ms
4,380 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 13 ms
4,380 KB
testcase_17 AC 15 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
constexpr ll mod = 1000000007;
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }

struct matrix {
    int n, m;
    vector<vector<ll>> dat;
    matrix(const vector<vector<ll>>& _a) : dat(_a) {
        n = dat.size(), m = dat.front().size();
    }
    matrix(const int& _n, const int& _m) : n(_n), m(_m) {
        dat = vec<ll>(n, m);
    }

    matrix operator*=(const matrix& a) {
        assert(m == a.n);
        matrix ret(vec<ll>(n, a.m));
        FOR(i, 0, n)FOR(k, 0, m)FOR(j, 0, a.m) {
            ret[i][j] += dat[i][k] * a.dat[k][j] % mod;
            if (mod <= ret[i][j])ret[i][j] -= mod;
        }
        return *this = ret;
    }
    matrix operator*(const matrix& a) { return matrix(*this) *= a; }

    matrix pow(ll k) const {
        assert(n == m);
        matrix ret(vec<ll>(n, n)), a(dat);
        FOR(i, 0, n)ret[i][i] = 1;
        for (; 0 < k; k >>= 1) {
            if (k & 1)ret*= a;
            a*= a;
        }
        return ret;
    }

    vector<ll>& operator[](int i) { return dat[i]; }
};

int main() {
    init();

    int m, k; cin >> m >> k;

    matrix x(m, m), y(m, m);
    x[0][0] = 1;
    FOR(i, 0, m)FOR(j, 0, m) {
        ++y[i][(i + j) % m];
        ++y[i][(i * j) % m];
    }

    print((x * y.pow(k))[0][0]);
}
0