結果

問題 No.262 面白くないビットすごろく
ユーザー mamekinmamekin
提出日時 2016-01-30 15:54:37
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,345 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 95,520 KB
実行使用メモリ 544,148 KB
最終ジャッジ日時 2023-10-21 17:58:15
合計ジャッジ時間 2,938 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    long long n;
    cin >> n;

    long long a = 1;
    long long cnt = 1;
    vector<vector<pair<long long, int> > > memo(32, vector<pair<long long, int> >(1<<20, make_pair(-1, -1)));
    while(a < n){
        int high = bitset<32>(a >> 20).count();
        int low = a & ((1 << 20) - 1);

        if(memo[high][low].first != -1){
            long long b = a + memo[high][low].first;
            if(b <= n){
                a = b;
                cnt += memo[high][low].second;
                continue;
            }
        }

        long long b = a;
        int add = 0;
        while(b < n && (a >> 20) == (b >> 20)){
            ++ add;
            b += high + bitset<32>(b & ((1 << 20) - 1)).count();
        }
        if((a >> 20) != (b >> 20))
            memo[high][low] = make_pair(b - a, add);
        a = b;
        cnt += add;
    }

    if(a == n)
        cout << cnt << endl;
    else
        cout << -1 << endl;

    return 0;
}
0