結果

問題 No.1050 Zero (Maximum)
ユーザー auauaauaua
提出日時 2020-05-08 22:25:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,295 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 171,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 03:06:59
合計ジャッジ時間 2,184 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll m,K;cin>>m>>K;
    vector<vector<vector<ll> > > nxt(34,vector<vector<ll> >(m,vector<ll>(m)));
    rep(i,34){
        rep(j,m){
            rep(k,m){
                if(i==0){
                    nxt[i][j][(j+k)%m]++;
                    nxt[i][j][j*k%m]++;
                }else{
                    rep(l,m){
                        nxt[i][j][k]=(nxt[i][j][k]+nxt[i-1][j][l]%mod*nxt[i-1][l][k])%mod;
                    }
                }
            }
        }
    }
    vector<ll>dp(m);
    vector<ll>dp1(m);
    dp[0]=1;
    rep(i,34){
        if((1LL<<i)&K){
            rep(j,m){
                rep(k,m){
                    dp1[k]=(dp1[k]+dp[j]*nxt[i][j][k]%mod)%mod;
                }
            }
            rep(j,m){
                dp[j]=dp1[j];
                dp1[j]=0;
            }
        }
    }
    cout<<dp[0]<<endl;
}
0