結果

問題 No.916 Encounter On A Tree
ユーザー tekihei2317tekihei2317
提出日時 2019-10-25 22:51:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 172,484 KB
実行使用メモリ 85,232 KB
最終ジャッジ日時 2023-10-11 07:22:16
合計ジャッジ時間 8,519 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 150 ms
84,944 KB
testcase_03 AC 149 ms
85,080 KB
testcase_04 AC 147 ms
84,928 KB
testcase_05 AC 149 ms
85,192 KB
testcase_06 AC 151 ms
85,056 KB
testcase_07 AC 149 ms
85,232 KB
testcase_08 AC 22 ms
13,348 KB
testcase_09 AC 41 ms
23,528 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 148 ms
85,072 KB
testcase_13 AC 149 ms
85,092 KB
testcase_14 AC 150 ms
85,088 KB
testcase_15 AC 149 ms
85,032 KB
testcase_16 AC 41 ms
23,540 KB
testcase_17 AC 148 ms
84,928 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 148 ms
85,076 KB
testcase_20 AC 150 ms
85,084 KB
testcase_21 AC 149 ms
84,924 KB
testcase_22 AC 148 ms
84,976 KB
testcase_23 AC 148 ms
85,088 KB
testcase_24 AC 149 ms
85,232 KB
testcase_25 AC 148 ms
85,088 KB
testcase_26 AC 77 ms
43,888 KB
testcase_27 AC 78 ms
44,056 KB
testcase_28 AC 41 ms
23,568 KB
testcase_29 AC 149 ms
84,976 KB
testcase_30 AC 148 ms
85,060 KB
testcase_31 AC 150 ms
85,112 KB
testcase_32 AC 148 ms
85,056 KB
testcase_33 AC 77 ms
44,080 KB
testcase_34 AC 40 ms
23,688 KB
testcase_35 AC 21 ms
13,228 KB
testcase_36 AC 150 ms
85,116 KB
testcase_37 AC 149 ms
84,924 KB
testcase_38 AC 41 ms
23,588 KB
testcase_39 AC 150 ms
85,020 KB
testcase_40 AC 150 ms
85,080 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 2 ms
4,352 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 22 ms
13,200 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,352 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 2 ms
4,352 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 2 ms
4,352 KB
testcase_58 AC 3 ms
4,352 KB
testcase_59 AC 5 ms
4,408 KB
testcase_60 AC 7 ms
5,592 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; }

const int mod=1e9+7;

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

    int d,l,r,k; cin>>d>>l>>r>>k;
    int n=1<<(d-1);
    vector<vector<int>> G(2*n);
    for(int i=1;i<n;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(2*n);
    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 heightL=32-__builtin_clz(l);
    int heightR=32-__builtin_clz(r);
    // cout<<heightL<<' '<<heightR<<endl;
    dfs(1<<(heightL-1),-1);
    // for(int i=1;i<2*n;i++) cout<<dist[i]<<' '; cout<<endl;

    int ans=0;
    for(int i=1<<(heightR-1);i<(1<<heightR);i++){
        if(dist[i]==k) ans++;
    }
    // cout<<ans<<endl;

    vector<int> fact(1<<d);
    fact[0]=1;
    for(int i=1;i<(1<<d);i++) fact[i]=fact[i-1]*i%mod;

    ans=ans*(1<<(heightL-1))%mod;
    // cout<<ans<<endl;
    for(int i=1;i<=d;i++){
        int j=1<<(i-1);
        if(i==heightL) j--;
        if(i==heightR) j--;
        // cout<<i<<' '<<j<<endl;
        ans=ans*fact[j]%mod;
    }
    cout<<ans<<endl;
}
0