結果

問題 No.916 Encounter On A Tree
ユーザー NOSSNOSS
提出日時 2019-10-25 22:35:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 168,160 KB
実行使用メモリ 11,480 KB
最終ジャッジ日時 2023-10-11 05:36:45
合計ジャッジ時間 4,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 10 ms
11,220 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 11 ms
11,480 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 10 ms
11,316 KB
testcase_08 AC 3 ms
4,356 KB
testcase_09 AC 5 ms
5,260 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 10 ms
11,360 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 11 ms
11,212 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 11 ms
11,224 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 11 ms
11,424 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 10 ms
11,200 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 10 ms
11,240 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 11 ms
11,316 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 6 ms
7,128 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 11 ms
11,176 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 5 ms
5,044 KB
testcase_35 AC 3 ms
4,352 KB
testcase_36 AC 11 ms
11,212 KB
testcase_37 AC 10 ms
11,316 KB
testcase_38 AC 5 ms
5,116 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 11 ms
11,392 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 4 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 1 ms
4,352 KB
testcase_52 AC 1 ms
4,348 KB
testcase_53 AC 1 ms
4,352 KB
testcase_54 AC 1 ms
4,352 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 2 ms
4,352 KB
testcase_58 AC 1 ms
4,348 KB
testcase_59 AC 1 ms
4,352 KB
testcase_60 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:16:5: 警告: ‘dr’ may be used uninitialized [-Wmaybe-uninitialized]
   16 |     if(dl > dr) swap(dl, dr);
      |     ^~
main.cpp:11:12: 備考: ‘dr’ はここで定義されています
   11 |     ll dl, dr;
      |            ^~
main.cpp:16:5: 警告: ‘dl’ may be used uninitialized [-Wmaybe-uninitialized]
   16 |     if(dl > dr) swap(dl, dr);
      |     ^~
main.cpp:11:8: 備考: ‘dl’ はここで定義されています
   11 |     ll dl, dr;
      |        ^~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr int INF = INT_MAX;
constexpr ll MOD = ll(1e9) + 7;

int main() {
    ll D, L, R, K;
    cin >> D >> L >> R >> K;
    ll dl, dr;
    for(int i=0;i<D;i++){
        if(L >= (1<<i) && L < (1<<(i+1))) dl = i+1;
        if(R >= (1<<i) && R < (1<<(i+1))) dr = i+1;
    }
    if(dl > dr) swap(dl, dr);
    ll lca = (dl+dr-K)/2;
    if(abs(dl-dr)%2 != K%2 || abs(dl-dr) > K || lca <= 0){
        cout << 0 << endl;
        return 0;
    }
    vector<ll> fact(1<<D);
    fact[0] = 1;
    for(ll i=1;i<=1<<D;i++){
        fact[i] = fact[i-1]*i%MOD;
    }
    ll ans = ((1LL<<max(dl-lca-1,0LL))%MOD)*((1LL<<max(dr-lca-1,0LL))%MOD) %MOD *((1LL<<(lca-1))*2%MOD) %MOD;
    for(int i=1;i<=D;i++){
        ll x = 1LL<<(i-1);
        if(i == dl) x--;
        if(i == dr) x--;
        ans *= fact[x];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0