結果

問題 No.1050 Zero (Maximum)
ユーザー first_vilfirst_vil
提出日時 2020-05-09 17:51:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,078 bytes
コンパイル時間 3,542 ms
コンパイル使用メモリ 232,204 KB
最終ジャッジ日時 2025-01-10 09:58:00
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#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