結果

問題 No.916 Encounter On A Tree
ユーザー Ogtsn99Ogtsn99
提出日時 2019-10-30 15:19:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,270 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 166,888 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-12 23:48:58
合計ジャッジ時間 3,714 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 7 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 7 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 7 ms
4,352 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 WA -
testcase_14 AC 1 ms
4,348 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 7 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 7 ms
4,352 KB
testcase_20 WA -
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 7 ms
4,352 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 7 ms
4,352 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 5 ms
4,356 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 8 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 WA -
testcase_37 AC 8 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 1 ms
4,352 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1 ms
4,352 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 WA -
testcase_48 AC 1 ms
4,348 KB
testcase_49 WA -
testcase_50 AC 2 ms
4,348 KB
testcase_51 WA -
testcase_52 AC 2 ms
4,352 KB
testcase_53 WA -
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 WA -
testcase_59 AC 2 ms
4,352 KB
testcase_60 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
long long kaijo(long long x){
    int p=1;
    while(x!=0){
        p*= x;
        p%=MOD;
        x--;
    }
    return p;
}
signed main(void){
    int d,l,r,k; cin>>d>>l>>r>>k;
    int ld=-1, rd=-1; //lとrの深さ
    vector <int> a(d+200); //深さdにいるノードの数
    for(int i=1;i<=20;i++){
        a[i-1] = (1LL << (i-1));
        if((1LL << (i-1)) <= l && l <= (1LL << (i)) - 1) ld = i;
        if((1LL << (i-1)) <= r && r <= (1LL << (i)) - 1) rd = i;
    }
    if(ld == -1 || rd == -1) {cout<<0<<endl; return 0;}
    int x;
    if(ld == rd){
        
        int dd = k/2;
        if(k&1||dd >= rd) {cout<<0<<endl; return 0;}
        //cout<<a[ld - dd -1]<<endl;
        if(ld - dd -1 <0) {cout<<0<<endl; return 0;}
        x = (2 * (1LL << (dd-1)) * (1LL << (dd-1)) % MOD * a[ld - dd - 1] + MOD) % MOD; //l,rの配置場所
        //cout<<x<<endl;
        a[ld - 1]-= 2;
    }else{
        
        /*if(rd - ld > k) {cout<<0<<endl; return 0;}
        if( (rd - ld) & 1){
            if(! (k & 1)) {cout<<0<<endl; return 0;}
            if( ! (rd - ld <= k && rd + ld - 2 >= k) ) {cout<<0<<endl; return 0;}
        } else if(k & 1) {cout<<0<<endl; return 0;}
        if(ld - 1 < 0 ) {cout<<0<<endl; return 0;}
        x = a[ld - 1] * (1LL << (rd - ld));*/
        int y = -1; //折り返し
        if(k == rd -ld) y = ld;
        else{

            if( (k - (rd - ld) )%2 == 1) {cout<<0<<endl; return 0;}
            else {y = (k -(rd - ld))/2;  y = ld - y;}
            if(y<=0) {cout<<0<<endl; return 0;}
            
        }
        x = a[ld - 1] * (1LL << (rd - y - 1));
        a[ld - 1]--, a[rd - 1]--;
    }
    
    int ans = x;
    rep(i,d){
        ans *= kaijo(a[i]);
        ans %= MOD;
    }
    
    cout<<ans<<endl;
}
0