結果
| 問題 |
No.262 面白くないビットすごろく
|
| コンテスト | |
| ユーザー |
Min_25
|
| 提出日時 | 2015-08-01 10:05:33 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 1,782 bytes |
| コンパイル時間 | 623 ms |
| コンパイル使用メモリ | 80,464 KB |
| 実行使用メモリ | 51,040 KB |
| 最終ジャッジ日時 | 2024-07-18 00:21:41 |
| 合計ジャッジ時間 | 1,277 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <utility>
#include <algorithm>
#include <queue>
#include <functional>
#include <vector>
#include <map>
#include <set>
#define getchar getchar_unlocked
#define putchar putchar_unlocked
using namespace std;
typedef long long int64;
typedef long long unsigned uint64;
typedef long double float80;
typedef unsigned short uint16;
typedef unsigned uint;
typedef unsigned char uint8;
const uint pre = 18;
const uint pre_total = 1u << pre;
uint nsteps[41 - pre][pre_total];
uint nexts[41 - pre][pre_total];
uint pops[1u << 16];
inline uint pop_count(uint n) {
return __builtin_popcount(n);
// return pops[n & 65535] + pops[n >> 16];
}
void solve() {
// @FF256grhy さんの解法
for (uint i = 0; i < 16; ++i) {
uint beg = 1 << i;
uint end = beg << 1;
for (uint j = beg; j < end; ++j) {
pops[j] = pops[j - beg] + 1;
}
}
for (int i = 40 - pre; i >= 0; --i) {
for (int j = pre_total - 1; j >= 0; --j) {
uint k = j + i + pop_count(j);
if (k >= pre_total) {
nsteps[i][j] = 1;
nexts[i][j] = k - pre_total;
} else {
nsteps[i][j] = nsteps[i][k] + 1;
nexts[i][j] = nexts[i][k];
}
}
}
uint64 n;
while (~scanf("%llu", &n)) {
uint hi = n >> pre;
uint lo = n & (pre_total - 1);
uint l = 1;
uint64 nstep = 1;
for (uint i = 0; i < hi; ++i) {
uint pc = pop_count(i);
nstep += nsteps[pc][l];
l = nexts[pc][l];
}
uint pc_hi = pop_count(hi);
while (l < lo) {
l += pc_hi + pop_count(l);
nstep += 1;
}
printf("%lld\n", l == lo ? nstep : -1);
}
}
int main() {
solve();
return 0;
}
Min_25