結果

問題 No.1050 Zero (Maximum)
ユーザー queeequeee
提出日時 2020-05-08 22:47:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 03:17:35
合計ジャッジ時間 1,588 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std; using ll=long long; const ll LNF=1e18; const int INF = 1e9+1; const ll M = 1e9+7;
typedef pair<int,int> P;

struct mat {
  vector<vector<ll>> v, v2;
  vector<ll> an, an2; int n;
  mat(int _n) : n(_n) {
    v.resize(n);
    for(int i=0;i<n;i++) v[i].resize(n);
    v2.resize(n);
    for(int i=0;i<n;i++) v2[i].resize(n);
    an.resize(n); an2.resize(n);
  }
  void initialize() {
    // 各自で調整
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        v[i][j]++;
      }
    }
    
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        v[i][i*j%n]++;
      }
    }

    an[0]=1;
  }
  void update() {
    //cout << "Updating...";
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++)
        v2[i][j]=0;
      //v2[i].assign(n, 0LL);
    }

    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        for(int k=0;k<n;k++) {
          v2[i][j] += v[i][k] * v[k][j] % M;
        }
        v2[i][j] %= M;
      }
    }

    v=v2;
    //cout << "Done!" << endl;
  }
  void update_ans() {
    //an2.assign(n, 0LL);
    for(int i=0;i<n;i++) {
      an2[i]=0;
    }
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        an2[i] += v[i][j] * an[j] % M;
      }
      an2[i] %= M;
    }
    an=an2;
  }
  void solve(ll x) {
    // x乗
    while(x>0) {
      if (x&1) update_ans();
      update();
      x>>=1;
    }
  }

  void print() {
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        cout << v[i][j]<<" ";
      } cout << endl;
    }

    for(int i=0;i<n;i++) {
      cout<<an[i]<<" ";
    } cout<<endl<<endl;
  }
};

int main() {
  ll m,k; cin>>m>>k;
  mat ma(m);
  ma.initialize();
  //ma.print();
  ma.solve(k);
  //ma.print();
  cout<<ma.an[0]<<endl;
}
0