結果

問題 No.916 Encounter On A Tree
ユーザー bin101bin101
提出日時 2019-10-25 23:05:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,564 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 68,012 KB
実行使用メモリ 19,168 KB
最終ジャッジ日時 2023-10-11 08:01:05
合計ジャッジ時間 4,245 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
18,980 KB
testcase_01 AC 18 ms
18,996 KB
testcase_02 AC 20 ms
19,036 KB
testcase_03 AC 19 ms
19,064 KB
testcase_04 AC 18 ms
18,968 KB
testcase_05 AC 19 ms
18,984 KB
testcase_06 AC 19 ms
19,056 KB
testcase_07 AC 18 ms
18,956 KB
testcase_08 AC 18 ms
18,928 KB
testcase_09 AC 19 ms
18,920 KB
testcase_10 AC 19 ms
18,920 KB
testcase_11 AC 18 ms
18,916 KB
testcase_12 AC 19 ms
18,988 KB
testcase_13 AC 20 ms
18,956 KB
testcase_14 AC 19 ms
18,972 KB
testcase_15 AC 18 ms
18,984 KB
testcase_16 AC 19 ms
18,920 KB
testcase_17 AC 19 ms
19,008 KB
testcase_18 AC 18 ms
19,168 KB
testcase_19 AC 19 ms
19,032 KB
testcase_20 AC 19 ms
18,916 KB
testcase_21 AC 18 ms
18,920 KB
testcase_22 AC 19 ms
18,956 KB
testcase_23 AC 18 ms
18,924 KB
testcase_24 AC 18 ms
18,920 KB
testcase_25 AC 18 ms
18,992 KB
testcase_26 AC 18 ms
18,912 KB
testcase_27 AC 18 ms
18,924 KB
testcase_28 AC 19 ms
18,920 KB
testcase_29 AC 19 ms
19,004 KB
testcase_30 AC 18 ms
18,928 KB
testcase_31 AC 19 ms
19,152 KB
testcase_32 AC 19 ms
18,976 KB
testcase_33 AC 19 ms
18,972 KB
testcase_34 AC 18 ms
18,920 KB
testcase_35 AC 19 ms
18,936 KB
testcase_36 AC 19 ms
18,952 KB
testcase_37 AC 18 ms
18,988 KB
testcase_38 AC 19 ms
18,920 KB
testcase_39 AC 19 ms
18,912 KB
testcase_40 AC 18 ms
18,940 KB
testcase_41 AC 18 ms
18,920 KB
testcase_42 AC 19 ms
19,004 KB
testcase_43 AC 19 ms
18,988 KB
testcase_44 AC 19 ms
18,916 KB
testcase_45 AC 19 ms
18,968 KB
testcase_46 AC 18 ms
19,152 KB
testcase_47 AC 18 ms
18,996 KB
testcase_48 AC 18 ms
18,980 KB
testcase_49 AC 19 ms
19,000 KB
testcase_50 AC 18 ms
19,040 KB
testcase_51 AC 19 ms
18,912 KB
testcase_52 AC 19 ms
18,940 KB
testcase_53 AC 18 ms
18,924 KB
testcase_54 AC 18 ms
19,048 KB
testcase_55 AC 19 ms
18,980 KB
testcase_56 AC 19 ms
18,920 KB
testcase_57 AC 20 ms
18,968 KB
testcase_58 AC 19 ms
18,980 KB
testcase_59 AC 19 ms
19,048 KB
testcase_60 AC 19 ms
19,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:14: warning: ‘rd’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     int d,ld,rd;
              ^~
main.cpp:68:14: warning: ‘ld’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     myplus[ld]--; myplus[rd]--;
     ~~~~~~~~~^

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
#define INF 100000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/

int myplus[30];

int main(){
    ll fact[2000000];
    fact[0]=1;
    for(ll i=1;i<2000000;i++){
        fact[i]=i*fact[i-1];
        fact[i]%=MOD;
    }

    int d,ld,rd;
    ll l,r,k,s[30],t[30];
    cin>>d>>l>>r>>k;

    s[1]=1LL; t[1]=1LL;
    for(int i=2;i<=d;i++){
        s[i]=s[i-1]*2;
        t[i]=t[i-1]*2+1;
    }
    for(int i=1;i<=d;i++){
        if(s[i]<=l && l<=t[i]) ld=i;
        if(s[i]<=r && r<=t[i]) rd=i;
    }
    bool flag=false;
    int temp=rd-ld;
    ll ans=1;
    int unko=1;
    for(int i=0;i<ld;i++){
        if(i>1) unko*=2;
        if(temp+i*2==k){
            flag=true;
            if(rd==ld){ //正しく機能
                if(i==1){
                    ans*=2*(t[rd]-s[rd]+1)/2;
                }else{
                    ans*=(t[rd]-s[rd]+1)*unko;
                }
            }else{
                //unko/=2;
                if(unko<1) unko=1;
                ans*=unko*(t[rd]-s[rd]+1);
            }
        } 
    }
    if(!flag){
        cout<<0<<endl;
        return 0;
    }
    myplus[ld]--; myplus[rd]--;
    for(int i=1;i<=d;i++){
        ans*=fact[t[i]-s[i]+1+myplus[i]];
        ans%=MOD;
    }
    cout<<ans<<endl;
}

0