結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
shira111
|
| 提出日時 | 2026-09-04 21:59:03 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| + 605µs | |
| コード長 | 693 bytes |
| 記録 | |
| コンパイル時間 | 2,453 ms |
| コンパイル使用メモリ | 356,280 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-04 21:59:14 |
| 合計ジャッジ時間 | 4,897 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
using namespace std;
typedef long long ll; typedef long double ld;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
int main() {
ios::sync_with_stdio(0); cin.tie(0); //入出力高速化
int N; cin>>N;
vi A(N+1, -1); A[0] = 0; A[1] = 1;
queue<int> Q; Q.push(1);
while(!Q.empty()) {
int i = Q.front(); Q.pop();
int p = __builtin_popcount(i);
int f = i + p, b = i - p;
if(f <= N && A[f] == -1) {
A[f] = A[i] + 1;
Q.push(f);
}
if(1 < b && A[b] == -1) {
A[b] = A[i] + 1;
Q.push(b);
}
}
cout<<A[N]<<endl;
}
shira111