結果

問題 No.3 ビットすごろく
ユーザー abinull
提出日時 2025-06-18 16:57:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 992 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 81,672 KB
実行使用メモリ 778,384 KB
最終ジャッジ日時 2025-06-18 16:57:38
合計ジャッジ時間 8,238 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 MLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

const int DONE = 20000;
const int YET = 0;

int main() {

  int n;
  unsigned int t;
  vector<pair<int, int>> sg;

  cin >> n;
  sg.resize(n);

  for (int i=0; i<n; i++) {
    t = i+1;
    sg[i].first = (int)__popcount(t);
    sg[i].second = YET;
  }

  queue<int> q;

  int i, u, m, cnt;
  q.push(0);
  u = 0; i = 0; m = 0; cnt = 0;
  
  while (!q.empty()) {

    u = q.front(); q.pop();
    sg[u].second = DONE;
    cnt++;   

    m = sg[u].first;

    if (m%2==0) {
      for (i=u; i<=u+m; i+=2) {
        if (i<0 || i>=sg.size()) continue;
        if (sg[i].second==DONE) continue;
        q.push(i);
      }
    }else {
      for (i=u+1; i<=u+m; i+=2) {
        if (i<0 || i>=sg.size()) continue;
        if (sg[i].second==DONE) continue;
        q.push(i);
      }    
    }
  } 

 if (u != sg.size()-1) {cout << -1 << endl;
 }else {cout << cnt << endl;}

  return 0;
}

0