結果

問題 No.916 Encounter On A Tree
ユーザー tekihei2317tekihei2317
提出日時 2019-10-29 20:28:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 2,201 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 173,684 KB
実行使用メモリ 85,260 KB
最終ジャッジ日時 2023-10-12 23:30:15
合計ジャッジ時間 7,965 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 146 ms
85,036 KB
testcase_03 AC 146 ms
85,140 KB
testcase_04 AC 147 ms
85,112 KB
testcase_05 AC 146 ms
85,052 KB
testcase_06 AC 146 ms
85,036 KB
testcase_07 AC 147 ms
85,000 KB
testcase_08 AC 21 ms
13,292 KB
testcase_09 AC 40 ms
23,664 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 146 ms
85,260 KB
testcase_13 AC 147 ms
84,976 KB
testcase_14 AC 146 ms
85,140 KB
testcase_15 AC 146 ms
85,124 KB
testcase_16 AC 40 ms
23,632 KB
testcase_17 AC 145 ms
85,060 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 146 ms
85,036 KB
testcase_20 AC 146 ms
85,096 KB
testcase_21 AC 145 ms
85,120 KB
testcase_22 AC 146 ms
85,152 KB
testcase_23 AC 146 ms
85,136 KB
testcase_24 AC 147 ms
85,052 KB
testcase_25 AC 147 ms
85,000 KB
testcase_26 AC 76 ms
43,968 KB
testcase_27 AC 74 ms
43,944 KB
testcase_28 AC 39 ms
23,428 KB
testcase_29 AC 145 ms
85,008 KB
testcase_30 AC 146 ms
85,004 KB
testcase_31 AC 146 ms
85,012 KB
testcase_32 AC 148 ms
85,124 KB
testcase_33 AC 75 ms
44,152 KB
testcase_34 AC 39 ms
23,520 KB
testcase_35 AC 21 ms
13,328 KB
testcase_36 AC 145 ms
84,996 KB
testcase_37 AC 151 ms
85,212 KB
testcase_38 AC 39 ms
23,448 KB
testcase_39 AC 145 ms
84,976 KB
testcase_40 AC 146 ms
84,976 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 21 ms
13,412 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,352 KB
testcase_48 AC 1 ms
4,352 KB
testcase_49 AC 1 ms
4,352 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 1 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 3 ms
4,352 KB
testcase_59 AC 4 ms
4,348 KB
testcase_60 AC 6 ms
5,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<int mod> class ModInt
{   
 private:
    int val;
 public:
    int value(){ return val; }
    ModInt(int x=0){ val=x%mod; }
    ModInt pow(int n){
        ModInt res(1),x(val);
        while(n>0){ if(n&1) res*=x; x*=x; n>>=1; }
        return res;
    }
    ModInt inv(){ return pow(mod-2); }
    ModInt& operator+=(ModInt rhs){ val+=rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator-=(ModInt rhs){ val+=mod-rhs.val; if(val>=mod) val-=mod; return *this; }
    ModInt& operator*=(ModInt rhs){ val=val*rhs.val%mod; return *this; }
    ModInt& operator/=(ModInt rhs){ *this*=rhs.inv(); return *this; }
    ModInt operator+(ModInt rhs){ return ModInt(val)+=rhs; }
    ModInt operator-(ModInt rhs){ return ModInt(val)-=rhs; }
    ModInt operator*(ModInt rhs){ return ModInt(val)*=rhs; }
    ModInt operator/(ModInt rhs){ return ModInt(val)/=rhs; }
};

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int d,l,r,k; cin>>d>>l>>r>>k;
    const int N=(1<<d)-1;
    vector<vector<int>> G(N+1);
    for(int i=1;i<1<<(d-1);i++){
        G[i].push_back(2*i);
        G[2*i].push_back(i);
        G[i].push_back(2*i+1);
        G[2*i+1].push_back(i);
    }
    
    vector<int> dist(N+1);
    function<void(int,int)> dfs=[&](int v,int p)
    {
        for(int u:G[v]) if(u!=p){
            dist[u]=dist[v]+1;
            dfs(u,v);
        }
    };

    int depthL=32-__builtin_clz(l);
    int depthR=32-__builtin_clz(r);
    dfs(1<<(depthL-1),-1);
    // for(int i=1;i<=N;i++) cout<<dist[i]<<' '; cout<<endl;

    using mint=ModInt<1000000007>;
    mint ans=0;
    for(int i=1<<(depthR-1);i<1<<depthR;i++) if(dist[i]==k) ans+=1;

    vector<mint> fact(N+1);
    fact[0]=1;
    for(int i=1;i<=N;i++) fact[i]=fact[i-1]*i;

    for(int i=1;i<=d;i++){
        int j=1<<(i-1);
        if(i==depthL) j--;
        if(i==depthR) j--;
        ans*=fact[j];
    }
    ans*=1<<(depthL-1);
    cout<<ans.value()<<endl;
    return 0;
}
0