結果

問題 No.916 Encounter On A Tree
ユーザー ttttan2ttttan2
提出日時 2019-10-25 23:03:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 3,137 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 146,896 KB
実行使用メモリ 24,040 KB
最終ジャッジ日時 2023-10-11 07:59:22
合計ジャッジ時間 4,769 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 44 ms
23,884 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 44 ms
23,828 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 43 ms
23,888 KB
testcase_08 AC 44 ms
23,908 KB
testcase_09 AC 44 ms
23,832 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 43 ms
23,828 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 43 ms
23,840 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 43 ms
23,900 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 43 ms
24,036 KB
testcase_18 AC 44 ms
23,840 KB
testcase_19 AC 44 ms
23,900 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 44 ms
23,960 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 44 ms
23,844 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 43 ms
23,952 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 43 ms
23,956 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 43 ms
23,840 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 46 ms
23,960 KB
testcase_35 AC 44 ms
23,904 KB
testcase_36 AC 42 ms
23,892 KB
testcase_37 AC 43 ms
23,840 KB
testcase_38 AC 44 ms
23,832 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 44 ms
23,896 KB
testcase_41 AC 43 ms
24,040 KB
testcase_42 AC 43 ms
23,964 KB
testcase_43 AC 45 ms
23,896 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 43 ms
23,892 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 44 ms
23,840 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 45 ms
24,032 KB
testcase_50 AC 43 ms
23,896 KB
testcase_51 AC 44 ms
23,832 KB
testcase_52 AC 44 ms
23,896 KB
testcase_53 AC 46 ms
23,832 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 43 ms
23,892 KB
testcase_56 AC 44 ms
23,832 KB
testcase_57 AC 44 ms
23,896 KB
testcase_58 AC 45 ms
23,888 KB
testcase_59 AC 44 ms
23,836 KB
testcase_60 AC 44 ms
23,896 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:149:25: warning: ‘der’ may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(i==del||i==der)y--;
                        ~^~~~~
main.cpp:157:26: warning: ‘del’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         ll ans=beki(2,k/2+del-1);
                       ~~~^~~~

ソースコード

diff #

#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

ll gya[2500010];
ll kai[2500010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll d,l,r,k;cin>>d>>l>>r>>k;
    ll del,der;
    ll now=1;
    rep(i,0,30){
        now*=2;
        if(now>l){
            del=i;
            break;
        }
    }
    ll noww=1;
    rep(i,0,30){
        noww*=2;
        if(noww>r){
            der=i;
            break;
        }
    }
    if(del+der<k){
        cout<<0<<endl;
        return 0;
    }
    if((del+der)%2!=k%2){
        cout<<0<<endl;
        return 0;
    }
    if(der-del>k){
        cout<<0<<endl;
        return 0;
    }
    nckinit(1100000);
  // cout<<del<<" "<<der<<endl;
    if(del!=der){
        ll s=der-del;
        ll rr=k-s;
        rr/=2;
        ll e;
        if(rr<=1)e=1;
        else e=beki(2,rr-1);
        e*=beki(2,s);
        e%=mod;
        
        ll ans=beki(2,del)*e;
        ans%=mod;
        rep(i,0,d){
            ll y=Pow(2,i);
            if(i==del||i==der)y--;
            ll yy=kai[y];
            ans*=yy;
            ans%=mod;
        }
        cout<<ans<<endl;
    }
    else{
        ll ans=beki(2,k/2+del-1);
        rep(i,0,d){
            ll y=Pow(2,i);
            if(i==del)y-=2;
            ll yy=kai[y];
            ans*=yy;
            ans%=mod;
        }
        cout<<ans<<endl;
    }
}
0