結果
| 問題 |
No.262 面白くないビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-01-30 15:54:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,345 bytes |
| コンパイル時間 | 752 ms |
| コンパイル使用メモリ | 97,256 KB |
| 実行使用メモリ | 544,160 KB |
| 最終ジャッジ日時 | 2024-09-21 19:13:04 |
| 合計ジャッジ時間 | 3,683 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 4 |
ソースコード
#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;
}