結果

問題 No.916 Encounter On A Tree
ユーザー mamekin
提出日時 2019-10-27 15:55:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 114,116 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 21:03:33
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge4 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int getDepth(int a)
{
    int d = 1;
    while((1 << d) <= a)
        ++ d;
    return d - 1;
}

const int MOD = 1000000007;

int main()
{
    int d, l, r, k;
    cin >> d >> l >> r >> k;

    l = getDepth(l);
    r = getDepth(r);
    if(k < r - l || (k - (r - l)) % 2 != 0){
        cout << 0 << endl;
        return 0;
    }

    int x = (k - (r - l)) / 2;
    if(l < x){
        cout << 0 << endl;
        return 0;
    }

    long long ans = 1LL << r;
    ans *= 1LL << max(0, x-1);
    ans %= MOD;
    for(int i=0; i<d; ++i){
        int n = 1 << i;
        if(l == i)
            -- n;
        if(r == i)
            -- n;
        for(int i=1; i<=n; ++i){
            ans *= i;
            ans %= MOD;
        }
    }
    cout << ans << endl;

    return 0;
}
0