結果
| 問題 | No.1694 ZerOne |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-10-05 15:27:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,138 bytes |
| 記録 | |
| コンパイル時間 | 1,275 ms |
| コンパイル使用メモリ | 104,888 KB |
| 実行使用メモリ | 84,508 KB |
| 最終ジャッジ日時 | 2024-07-23 02:34:52 |
| 合計ジャッジ時間 | 4,781 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 30 |
ソースコード
/* -*- 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;
}
tnakao0123