結果

問題 No.2067 ±2^k operations
ユーザー gs15120gs15120
提出日時 2022-09-14 15:15:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,900 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 187,324 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 14:28:01
合計ジャッジ時間 5,317 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 11 ms
4,384 KB
testcase_02 AC 11 ms
4,384 KB
testcase_03 AC 11 ms
4,380 KB
testcase_04 AC 11 ms
4,384 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 9 ms
4,380 KB
testcase_07 AC 21 ms
4,380 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 21 ms
4,380 KB
testcase_10 AC 21 ms
4,384 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 20 ms
4,380 KB
testcase_13 AC 20 ms
4,384 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 21 ms
4,384 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 7 ms
4,384 KB
testcase_21 AC 18 ms
4,384 KB
testcase_22 AC 17 ms
4,380 KB
testcase_23 AC 18 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lll long long//__int128
#define pii pair<int,int>
//#define f first
#define s second
# define pi 3.14159265358979323846
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

struct chash_key
{
    ll operator()(pii x) const { return (ll)x.first*1000000000   + x.second; }
};
//gp_hash_table<pii,int,chash_key> hs[2],p[2];

//gp_hash_table<ll,int> dp;

/*
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);

cout << fixed;
	cout.precision(3);
	cout << x << '\n';
*/
struct P
{
    int x,y,z;
    bool operator <(const P &a)const
    {
        return y>a.y;
    };
};

int a,b,c;

int o[66];
ll dp[60][2][2],one=1,y;

ll f(int n,int c,int d)
{
    if(n<0)
    {
        return 0;
    }
    if(dp[n][c][d]>=0) return dp[n][c][d];
    ll x=0;

    if(!d)
    {
        if(!o[n])
        {
            if(n==0) x=0;
            else if(c==0) x=f(n-1,0,0);
            else if(o[n-1]==1)
            {
                x+=f(n-2,0,1);
                x+=f(n-2,1,0)+(((one<<(n-1))-1)&y)+1;

            }
            else
            {
                x=f(n-2,0,0);
            }
        }
        else if(c==0)
        {
            x=f(n-1,c,1);

            if(n==0) x+=f(n-1,0,0)+1;
            else if(o[n-1]==1)
            {
                x+=f(n-2,0,1)+(one<<(n-1));
                /*if(y==13)
                {
                    cout<<(((one<<(n-1))-1)&y)*2+2<<"##\n";
                }
                if(y==12)
                {
                    cout<<(((one<<(n-1))-1)&y)*2+2<<"##\n";
                }*/
                x+=f(n-2,1,0)+(((one<<(n-1))-1)&y)*2+2;
            }
            else
            {
                x+=f(n-2,0,0)+(((one<<(n-1))-1)&y)+1;
            }
        }
        else
        {
            x=f(n-1,1,0);

            if(n==0) x+=f(n-1,0,0);
            else
            {
                x+=f(n-2,1,1)+(one<<(n-1));
                x+=f(n-2,0,1);
            }
        }
    }
    else
    {
        if(c==0)
        {
            x=f(n-1,c,1);
            if(n==0) x+=f(n-1,0,0)+1;
            else
            {
                x+=f(n-2,0,1)+(one<<(n-1));
                x+=f(n-2,1,1)+(one<<(n-1))*2;
            }
        }
        else
        {
            x=f(n-1,1,1);

            if(n==0) x+=f(n-1,0,0);
            else
            {
                x+=f(n-2,1,1)+(one<<(n-1));
                x+=f(n-2,0,1);
            }
        }
    }



    return dp[n][c][d]=x;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);

    int ttt=100;
    cin>>ttt;


    for(int tt=1;tt<=ttt;tt++)
    {

        memset(dp,-1,sizeof(dp));
        cin>>y;
        //y=tt;
        for(int i=0;i<60;i++)
        {
            if(y&(one<<i)) o[i]=1;
            else o[i]=0;
        }
        cout<<f(59,0,0)<<"\n";
    }

}
//13 14
//1101
0