結果
| 問題 | No.3789 Binary 0-count Sequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-06 22:12:29 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,894 bytes |
| 記録 | |
| コンパイル時間 | 1,635 ms |
| コンパイル使用メモリ | 221,188 KB |
| 実行使用メモリ | 9,928 KB |
| 最終ジャッジ日時 | 2026-11-06 22:12:33 |
| 合計ジャッジ時間 | 3,959 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge7_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 WA * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
int N; cin >> N;
vector<int> A(N);
for(auto &a : A) cin >> a;
auto check = [&](long long x) -> bool {
for(int i=0; i<N; i++){
long long now = 0,v = x+i;
if(v < 0) return false;
if(v == 0) now = 1;
else while(v) now += v%2==0,v >>= 1;
if(A.at(i) == now) continue;
return false;
}
return true;
};
if(check(0)){cout << "0\n"; continue;}
if(N == 1 || (N == 2 && A.at(1)-A.at(0) == -1)){cout << (1LL<<A.at(0)) << "\n"; continue;}
vector<int> dec;
int even = -1;
{
bool ok = true;
for(int i=1; i<N; i+=2){
if(A.at(i)-A.at(i-1) == -1) continue;
ok = false; break;
}
for(int i=2; i<N; i+=2){
if(A.at(i)-A.at(i-1) >= 0) continue;
ok = false; break;
}
if(ok) even = 0;
}
{
bool ok = true;
for(int i=2; i<N; i+=2){
if(A.at(i)-A.at(i-1) == -1) continue;
ok = false; break;
}
for(int i=1; i<N; i+=2){
if(A.at(i)-A.at(i-1) >= 0) continue;
ok = false; break;
}
if(ok) even = 1;
}
if(even == -1){cout << "-1\n"; continue;}
if(even == 0){
int maxd = -1;
for(int i=2; i<N; i+=2) maxd = max(maxd,A.at(i)-A.at(i-1));
for(int i=2; i<N; i+=2) if(maxd == A.at(i)-A.at(i-1)){
long long v = 1LL<<maxd;
if(check(v-i)){cout << v-i << "\n"; break;}
if(A.at(i) == maxd){cout << "-1\n"; break;}
int more = A.at(i)-maxd;
long long d = maxd+1;
v = 1LL<<d;
d += more+1;
v += 1LL<<d;
if(check(v-i)) cout << v-i << "\n";
else cout << "-1\n";
break;
}
}
else{
int maxd = -1;
for(int i=1; i<N; i+=2) maxd = max(maxd,A.at(i)-A.at(i-1));
for(int i=1; i<N; i+=2) if(maxd == A.at(i)-A.at(i-1)){
long long v = 1LL<<maxd;
if(check(v-i)){cout << v-i << "\n"; break;}
if(A.at(i) == maxd){cout << "-1\n"; break;}
int more = A.at(i)-maxd;
long long d = maxd+1;
v = 1LL<<d;
d += more+1;
v += 1LL<<d;
if(check(v-i)) cout << v-i << "\n";
else cout << "-1\n";
break;
}
}
}
}