結果
問題 | No.916 Encounter On A Tree |
ユーザー | kappybar |
提出日時 | 2020-04-17 15:02:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,510 bytes |
コンパイル時間 | 1,500 ms |
コンパイル使用メモリ | 168,196 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-10-03 10:18:55 |
合計ジャッジ時間 | 4,420 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
26,808 KB |
testcase_01 | AC | 23 ms
26,880 KB |
testcase_02 | AC | 23 ms
26,864 KB |
testcase_03 | AC | 22 ms
26,960 KB |
testcase_04 | AC | 22 ms
26,876 KB |
testcase_05 | AC | 23 ms
26,988 KB |
testcase_06 | AC | 21 ms
26,880 KB |
testcase_07 | AC | 20 ms
26,880 KB |
testcase_08 | AC | 23 ms
26,880 KB |
testcase_09 | AC | 21 ms
26,840 KB |
testcase_10 | AC | 22 ms
26,896 KB |
testcase_11 | AC | 22 ms
26,752 KB |
testcase_12 | AC | 21 ms
26,880 KB |
testcase_13 | AC | 20 ms
26,752 KB |
testcase_14 | AC | 21 ms
26,848 KB |
testcase_15 | AC | 21 ms
26,880 KB |
testcase_16 | AC | 20 ms
26,880 KB |
testcase_17 | AC | 21 ms
26,880 KB |
testcase_18 | AC | 20 ms
26,820 KB |
testcase_19 | AC | 20 ms
26,864 KB |
testcase_20 | AC | 21 ms
26,880 KB |
testcase_21 | AC | 22 ms
26,880 KB |
testcase_22 | AC | 20 ms
26,724 KB |
testcase_23 | AC | 20 ms
26,940 KB |
testcase_24 | AC | 22 ms
26,776 KB |
testcase_25 | AC | 20 ms
26,880 KB |
testcase_26 | AC | 22 ms
26,752 KB |
testcase_27 | AC | 21 ms
26,880 KB |
testcase_28 | AC | 22 ms
26,880 KB |
testcase_29 | AC | 22 ms
26,812 KB |
testcase_30 | AC | 21 ms
26,880 KB |
testcase_31 | AC | 21 ms
27,008 KB |
testcase_32 | AC | 21 ms
26,880 KB |
testcase_33 | AC | 21 ms
26,880 KB |
testcase_34 | AC | 21 ms
26,880 KB |
testcase_35 | AC | 22 ms
26,784 KB |
testcase_36 | AC | 21 ms
26,880 KB |
testcase_37 | AC | 21 ms
26,880 KB |
testcase_38 | AC | 22 ms
26,880 KB |
testcase_39 | AC | 23 ms
26,880 KB |
testcase_40 | AC | 23 ms
26,752 KB |
testcase_41 | AC | 22 ms
26,880 KB |
testcase_42 | AC | 23 ms
26,880 KB |
testcase_43 | AC | 22 ms
26,752 KB |
testcase_44 | AC | 22 ms
26,752 KB |
testcase_45 | AC | 21 ms
26,880 KB |
testcase_46 | AC | 21 ms
26,880 KB |
testcase_47 | AC | 21 ms
26,880 KB |
testcase_48 | AC | 23 ms
26,880 KB |
testcase_49 | AC | 22 ms
26,880 KB |
testcase_50 | AC | 20 ms
26,880 KB |
testcase_51 | AC | 20 ms
26,880 KB |
testcase_52 | AC | 20 ms
27,008 KB |
testcase_53 | AC | 21 ms
26,720 KB |
testcase_54 | AC | 21 ms
26,836 KB |
testcase_55 | AC | 22 ms
26,752 KB |
testcase_56 | AC | 22 ms
26,752 KB |
testcase_57 | AC | 22 ms
26,880 KB |
testcase_58 | AC | 22 ms
26,880 KB |
testcase_59 | AC | 23 ms
26,856 KB |
testcase_60 | AC | 23 ms
26,888 KB |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using ll = long long ; using P = pair<int,int> ; const int INF = 1e9; const int MOD = 1000000007; ll fac[3000000]; void init(){ fac[0] = 1; fac[1] = 1; for(int i=2;i<3000000;i++){ fac[i] = (fac[i-1] * i)%MOD; } } int depth(int p){ int i = 0; int res = 1; while(res <= p){ res *= 2; i ++; } return i; } ll power(int n,int k){ ll res = 1; for(int i=0;i<k;i++) res = (res * n)%MOD; return res; } int main(){ init(); int d,l,r,k; cin >> d >> l >> r >> k; int ld = depth(l); int rd = depth(r); //cout << ld << " "<< rd << endl; if((k-(rd-ld))%2 == 0 && ld - (k-(rd-ld))/2 >= 1 && rd-ld <= k){ int lca_d = ld - (k-(rd-ld))/2 ; //cout << lca_d << endl; ll ans; if(lca_d == ld) ans = (power(2,ld-1) * (power(2,rd-ld)))%MOD; else ans = (((power(2,lca_d-1) * power(2,ld-lca_d-1))%MOD * power(2,rd-lca_d-1))%MOD * 2)%MOD; //cout << lca_d-1 << " " << ld-lca_d-1 << " " << rd-lca_d-1 << endl; //cout << ans << endl; ll res = 2; for(ll i=2;i<=d;i++){ if(i==ld && i==rd) ans = (ans * fac[res-2])%MOD; else if(i==ld || i==rd) ans = (ans * fac[res-1])%MOD; else ans = (ans * fac[res])%MOD; res *= 2; } cout << ans << endl; }else{ cout << 0 << endl; return 0; } return 0; }