結果
| 問題 |
No.262 面白くないビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-01-30 15:50:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 111 ms / 2,000 ms |
| コード長 | 1,339 bytes |
| コンパイル時間 | 902 ms |
| コンパイル使用メモリ | 100,744 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-09-21 19:13:00 |
| 合計ジャッジ時間 | 1,612 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 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;
map<pair<int, int>, pair<long long, int> > memo;
while(a < n){
int high = bitset<32>(a >> 20).count();
int low = a & ((1 << 20) - 1);
if(memo.find(make_pair(high, low)) != memo.end()){
long long b = a + memo[make_pair(high, low)].first;
if(b <= n){
a = b;
cnt += memo[make_pair(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[make_pair(high, low)] = make_pair(b - a, add);
a = b;
cnt += add;
}
if(a == n)
cout << cnt << endl;
else
cout << -1 << endl;
return 0;
}