結果

問題 No.916 Encounter On A Tree
ユーザー Ogtsn99Ogtsn99
提出日時 2019-10-30 14:37:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,728 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 167,236 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-10-12 23:44:23
合計ジャッジ時間 7,753 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 8 ms
4,356 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 7 ms
4,352 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 3 ms
4,352 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 8 ms
4,376 KB
testcase_16 RE -
testcase_17 WA -
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,352 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,348 KB
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 AC 1 ms
4,352 KB
testcase_31 WA -
testcase_32 AC 2 ms
4,348 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 WA -
testcase_36 AC 7 ms
4,348 KB
testcase_37 AC 8 ms
4,356 KB
testcase_38 RE -
testcase_39 AC 1 ms
4,352 KB
testcase_40 AC 7 ms
4,352 KB
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 3 ms
4,352 KB
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 WA -
testcase_58 AC 1 ms
4,372 KB
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:36:15: 警告: ‘rd’ may be used uninitialized [-Wmaybe-uninitialized]
   36 |         if(k&1||dd >= rd) {cout<<0<<endl; return 0;}
      |            ~~~^~~~~~~~~~
main.cpp:25:13: 備考: ‘rd’ はここで定義されています
   25 |     int ld, rd; //lとrの深さ
      |             ^~
main.cpp:41:14: 警告: ‘ld’ may be used uninitialized [-Wmaybe-uninitialized]
   41 |         a[ld - 1]-= 2;
      |           ~~~^~~
main.cpp:25:9: 備考: ‘ld’ はここで定義されています
   25 |     int ld, rd; //lとrの深さ
      |         ^~

ソースコード

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, rd; //lとrの深さ
    vector <int> a(d); //深さ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;
    }
    int x;
    if(ld == rd){
        //cout<<"+"<<endl;
        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)) * a[ld - dd - 1] + MOD) % MOD; //l,rの配置場所
        //cout<<x<<endl;
        a[ld - 1]-= 2;
    }else{
        if( (rd - ld) & 1){
            if(! (k & 1)) {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));
        a[ld - 1]--, a[rd - 1]--;
    }
    
    int ans = x;
    rep(i,d){
        ans *= kaijo(a[i]);
        ans %= MOD;
    }
    
    cout<<ans<<endl;
}
0