結果
| 問題 | No.3789 Binary 0-count Sequence |
| コンテスト | |
| ユーザー |
DeltaStruct
|
| 提出日時 | 2026-11-06 17:25:20 |
| 言語 | C++23(gnu拡張) (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 52 ms / 3,000 ms |
| + 386µs | |
| コード長 | 1,393 bytes |
| 記録 | |
| コンパイル時間 | 2,508 ms |
| コンパイル使用メモリ | 342,488 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2026-11-06 21:13:24 |
| 合計ジャッジ時間 | 4,422 ms |
|
ジャッジサーバーID (参考情報) |
judge7_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int t; cin >> t;
while(t--) []{
int n; cin >> n;
vector<int> A(n); for (int& a:A) cin >> a;
auto f = [](long long x) -> int {
return (x?64-__builtin_clzll(x)-__builtin_popcountll(x):1);
};
cout << [&f](this auto self,vector<int>& A) -> long long {
if (*min_element(A.begin(),A.end())<0) return -1;
int n = A.size();
if (n==1) return (A[0]!=1?1ll<<A[0]:0ll);
if (n==2){
if (A[0]>A[1]+1) return -1;
if (A[0]==0) return (A[1]?(1ll<<A[1])-1:-1ll);
if (A[0]==1&&A[1]==0) return 0;
return (1ll<<(A[1]+1))+(1ll<<(A[1]-A[0]+1))-1;
}
bool is0 = true,is1 = true;
for (int i(0);i < n;++i){
if (A[i]!=f(i)) is0 = false;
if (A[i]!=f(i+1)) is1 = false;
}
if (is0) return 0;
if (is1) return 1;
vector<int> B;
for (int i(0);i < n;i+=2) if (i+1==n||A[i+1]==A[i]-1) B.emplace_back(A[i]-1);
if (B.size()==(n+1)/2){
long long res = self(B);
if (res>0) return 2*res;
if (res==0&&n<=4) return 4;
}
B.clear();
B.emplace_back(A[0]);
for (int i(1);i < n;i+=2) if (i+1==n||A[i+1]==A[i]-1) B.emplace_back(A[i]-1);
if (B.size()==n/2+1){
long long res = self(B);
if (res>0) return 2*res+1;
if (res==0&&n==3) return 5;
}
return -1;
}(A) << '\n';
}();
}
DeltaStruct