結果

問題 No.916 Encounter On A Tree
ユーザー IKyoproIKyopro
提出日時 2019-10-25 22:56:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 2,680 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 75,128 KB
実行使用メモリ 11,576 KB
最終ジャッジ日時 2023-10-11 07:33:08
合計ジャッジ時間 3,905 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 10 ms
11,276 KB
testcase_03 AC 11 ms
11,576 KB
testcase_04 AC 11 ms
11,276 KB
testcase_05 AC 11 ms
11,276 KB
testcase_06 AC 11 ms
11,284 KB
testcase_07 AC 11 ms
11,284 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 5 ms
5,268 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 11 ms
11,228 KB
testcase_13 AC 11 ms
11,340 KB
testcase_14 AC 11 ms
11,220 KB
testcase_15 AC 10 ms
11,284 KB
testcase_16 AC 5 ms
5,268 KB
testcase_17 AC 10 ms
11,332 KB
testcase_18 AC 2 ms
4,356 KB
testcase_19 AC 10 ms
11,336 KB
testcase_20 AC 10 ms
11,280 KB
testcase_21 AC 10 ms
11,404 KB
testcase_22 AC 10 ms
11,404 KB
testcase_23 AC 11 ms
11,284 KB
testcase_24 AC 11 ms
11,276 KB
testcase_25 AC 10 ms
11,404 KB
testcase_26 AC 7 ms
7,252 KB
testcase_27 AC 7 ms
7,192 KB
testcase_28 AC 5 ms
5,152 KB
testcase_29 AC 11 ms
11,228 KB
testcase_30 AC 10 ms
11,280 KB
testcase_31 AC 10 ms
11,272 KB
testcase_32 AC 11 ms
11,336 KB
testcase_33 AC 6 ms
7,140 KB
testcase_34 AC 5 ms
5,096 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 11 ms
11,408 KB
testcase_37 AC 10 ms
11,396 KB
testcase_38 AC 4 ms
5,136 KB
testcase_39 AC 11 ms
11,216 KB
testcase_40 AC 11 ms
11,400 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,352 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 4 ms
4,376 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 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,352 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 ms
4,352 KB
testcase_53 AC 2 ms
4,356 KB
testcase_54 AC 1 ms
4,352 KB
testcase_55 AC 2 ms
4,352 KB
testcase_56 AC 1 ms
4,352 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,352 KB
testcase_60 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:92:8: 警告: ‘dr’ may be used uninitialized [-Wmaybe-uninitialized]
   92 |     ll d = dl-dr;
      |        ^
main.cpp:82:19: 備考: ‘dr’ はここで定義されています
   82 |     ll D,L,R,K,dl,dr;
      |                   ^~
main.cpp:92:8: 警告: ‘dl’ may be used uninitialized [-Wmaybe-uninitialized]
   92 |     ll d = dl-dr;
      |        ^
main.cpp:82:16: 備考: ‘dl’ はここで定義されています
   82 |     ll D,L,R,K,dl,dr;
      |                ^~

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,finv;
public:
    combination(int N){
        fact = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            finv[i] = fact[i].inv();
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    ll D,L,R,K,dl,dr;
    cin >> D >> L >> R >> K;
    if(L<R) swap(L,R);
    for(int i=0;i<D;i++){
        int mi = (1<<i),ma = (1<<(i+1))-1;
        if(mi<=L && L<=ma) dl = i;
        if(mi<=R && R<=ma) dr = i;
    }
    vector<mint> fact(1<<D,1);
    for(ll i=1;i<(1<<D);i++) fact[i] = fact[i-1]*i;
    ll d = dl-dr;
    
    K -= d;
    if(K<0 || K%2){
        cout << 0 << endl;
        return 0;
    }
    if(2*dr<K){
        cout << 0 << endl;
        return 0;
    }
    K /= 2;
    ll cnt;
    if(K==0) cnt = 1;
    else cnt = (1<<K)-(1<<(K-1));
    mint ans = 1;
    //cerr << dl << " " << dr << " " << cnt << endl;
    for(int i=0;i<D;i++){
        if(i==dr){
            mint p;
            if(dr==0) p = 1;
            else if(dr!=dl) p = fact[(1<<dr)-1];
            else p = fact[(1<<dr)-2]*(1<<dl);
            ans *= p*cnt;
        }else ans *= fact[1<<i];
    }
    cout << ans.x << endl;
}
0