結果

問題 No.1694 ZerOne
ユーザー tnakao0123tnakao0123
提出日時 2021-10-05 15:27:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,138 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 100,884 KB
実行使用メモリ 82,192 KB
最終ジャッジ日時 2023-09-30 08:31:32
合計ジャッジ時間 6,016 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1694.cc:  No.1694 ZerOne - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 60;
const int BN = 16;
const int BBITS = 1 << BN;
const int BMSK = BBITS - 1;

/* typedef */

typedef long long ll;
typedef queue<ll> ql;
typedef set<ll> sl;

/* global variables */

char s[MAX_N + 4];
int bnums[BBITS];
ll msks[MAX_N + 1];
sl as;

/* subroutines */

inline ll getbits(ll bits, int i, int l) {
  return (bits >> i) & msks[l];
}

inline int cntbits(ll bits) {
  return
    bnums[bits & BMSK] + bnums[(bits >> BN) & BMSK] +
    bnums[(bits >> (BN * 2)) & BMSK] + bnums[(bits >> (BN * 3)) & BMSK];
}

/* main */

int main() {
  bnums[0] = 0;
  for (int bits = 1, msb = 1; bits < BBITS; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }
  
  scanf("%s", s);
  int n = strlen(s), hn = n / 2;

  ll st = 0;
  for (int i = 0; i < n; i++) {
    int si = s[i] - '0';
    msks[i + 1] = ((1LL << (i + 1)) - 1);
    st |= ((ll)si << i);
  }
  //printf("n=%d, st=0x%llx\n", n, st);

  as.insert(st);
  ql q;
  q.push(st);

  while (! q.empty()) {
    ll u = q.front(); q.pop();

    for (int l = 1; l <= hn; l++)
      for (int i = 0; i + 2 * l <= n; i++) {
	ll bitsi = getbits(u, i, l);
	int ci = cntbits(bitsi);
	for (int j = i + l; j + l <= n; j++) {
	  ll bitsj = getbits(u, j, l);
	  int cj = cntbits(bitsj);
	  if (bitsi != bitsj && ci == cj) {
	    ll v =
	      (u & ~(msks[l] << i) & ~(msks[l] << j)) |
	      (bitsi << j) | (bitsj << i);
	    //printf("u=0x%llx, l=%d i=%d,0x%llx,%d j=%d,0x%llx,%d -> v=0x%llx\n",
	    //u, l, i, bitsi, ci, j, bitsj, cj, v);

	    if (! as.count(v)) {
	      as.insert(v);
	      q.push(v);
	    }
	  }
	}
      }
  }

  printf("%lu\n", as.size());
  //for (auto u: as) printf(" 0x%llx\n", u);
  return 0;
}
0