結果
| 問題 | No.3789 Binary 0-count Sequence |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-10-31 09:33:56 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 6,279 bytes |
| 記録 | |
| コンパイル時間 | 2,890 ms |
| コンパイル使用メモリ | 220,628 KB |
| 実行使用メモリ | 32,276 KB |
| 最終ジャッジ日時 | 2026-11-06 21:11:37 |
| 合計ジャッジ時間 | 7,874 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 WA * 6 |
ソースコード
#include <algorithm>
#include <atcoder/all>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vvpii vector<vector<pair<int, int>>>
#define vvpll vector<vector<pair<ll, ll>>>
template <typename T>
void debug(T e) {
cerr << e << endl;
}
template <typename T>
void debug(vector<T> &v) {
rep(i, v.size()) { cerr << v[i] << " "; }
cerr << endl;
}
template <typename T>
void debug(vector<vector<T>> &v) {
rep(i, v.size()) {
rep(j, v[i].size()) { cerr << v[i][j] << " "; }
cerr << endl;
}
}
template <typename T>
void debug(vector<pair<T, T>> &v) {
rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; }
}
template <typename T>
void debug(set<T> &st) {
for (auto itr = st.begin(); itr != st.end(); itr++) {
cerr << *itr << " ";
}
cerr << endl;
}
template <typename T>
void debug(multiset<T> &ms) {
for (auto itr = ms.begin(); itr != ms.end(); itr++) {
cerr << *itr << " ";
}
cerr << endl;
}
template <typename T>
void debug(map<T, T> &mp) {
for (auto itr = mp.begin(); itr != mp.end(); itr++) {
cerr << itr->first << " " << itr->second << endl;
}
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << H << " ";
debug_out(T...);
}
using mint = modint998244353;
void debug_mint1(vector<mint> &vec) {
for (int i = 0; i < vec.size(); i++) {
cerr << vec[i].val() << " ";
}
cerr << endl;
}
void debug_mint2(vector<vector<mint>> &vec) {
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < vec[i].size(); j++) {
cerr << vec[i][j].val() << " ";
}
cerr << endl;
}
}
// 回数を持って dfs する。そのとき、top の要素がどれだけずれたかも情報として持つ
ll dfs(ll times, ll top, vector<ll> &vec, vector<ll> &true_seq){
// debug_out(times, top);
assert(times <= 200);
ll len = vec.size();
for (ll i = 0; i < len; i++){
vec[i] -= times;
}
// まず先頭が 0 の場合を試す
if (times == 0){
bool all_same = true;
for (ll i = 0; i < len; i++){
if (vec[i] != true_seq[i]){
all_same = false;
}
}
if (all_same) return 0;
}
// そうでない場合は規則的
// 長さが 2 の場合の答えを求めたい!
if (len == 2){
if (vec[0] == 0 && vec[1] == 0){
return -1;
}
else if (vec[0] == 0){
return ((1LL << vec[1]) - 1) * (1LL << times) - top;
}
else if (vec[0] == vec[1]){
return ((1LL << (vec[0] + 1)) + 1) * (1LL << times) - top;
}
else if (vec[0] == vec[1] + 1){
return (1LL << vec[0]) * (1LL << times) - top;
}
else if (vec[0] < vec[1]){
return ((1LL << (vec[1] + 1)) + (1LL << (vec[1] - vec[0] + 1)) - 1) * (1LL << times) - top;
}
else return -1;
}
vector<ll> odd_vec;
vector<ll> even_vec;
even_vec.push_back(vec[0] + 1 + times);
rep(i, len){
if (i % 2 == 0) odd_vec.push_back(vec[i] + times);
else even_vec.push_back(vec[i] + times);
}
bool pos_0 = true;
for (ll i = 0; i < len; i += 2){
if (i < len - 1){
if (vec[i] != vec[i + 1] + 1){
pos_0 = false;
}
}
}
if (pos_0){
return dfs(times + 1, top, odd_vec, true_seq);
}
bool pos_1 = true;
for (ll i = 1; i < len; i += 2){
if (i < len - 1){
if (vec[i] != vec[i + 1] + 1){
pos_1 = false;
}
}
}
if (pos_1){
return dfs(times + 1, top - (1LL << times), even_vec, true_seq);
}
return -1;
}
int main() {
ll T;
cin >> T;
// 実際に数列を構成してしまう
ll L = 1000001;
vector<ll> true_seq(L, 0);
for (ll i = 0; i < L; i++){
ll top = -1;
for (ll j = 0; j < 20; j++){
if ((i >> j) & 1) top = j;
}
for (ll j = 0; j <= top; j++){
if (!((i >> j) & 1)){
true_seq[i]++;
}
}
}
true_seq[0]++;
/*for (ll i = 0; i < 64; i++){
cout << true_seq[i] << " ";
}
cout << endl;*/
while (T--){
// (1, 0, 1, 0, 2, 1, 1, 0, 3, 2, 2, 1, ...)
// (1, 1, 2, 1, 3, 2, 2, 1, 4, 3, 3, 2, ...)
// (1, 2, 3, 2, 4, 3, 3, 2, 5, 4, 4, 3, ...)
// (1, 3, 4, 3, 5, 4, 4, 3, 6, 5, 5, 4, ...)
// 先頭の要素を除いては 1 ずつ増えていっている!
// つまり、何番目の再帰であるかを別で持っておけば答えられそう。
ll N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
if (N == 1){
if (A[0] == 1){
cout << 0 << endl;
}
else{
cout << (1LL << A[0]) << endl;
}
}
else{
ll ans = dfs(0, 0, A, true_seq);
cout << ans << endl;
}
}
}