QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#938683 | #10155. Bit Counting Sequence | ElevenX | WA | 16ms | 5248kb | C++20 | 1.7kb | 2025-03-17 02:48:54 | 2025-03-17 02:49:05 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
bool isValid(vector<int>& a) {
int n = a.size();
for (int i = 0; i < n; i++) {
if (a[i] < 0 || a[i] > 60) return false;
}
return true;
}
// Function to count bits in a number
int countBits(ll x) {
int count = 0;
while (x) {
count += x & 1;
x >>= 1;
}
return count;
}
// Special case handler for (60,60)
ll handle_60_60_case() {
// 2^61 - 3 will have 60 ones (all bits up to position 60 except position 1)
return (1LL << 61) - 3;
}
ll solve_case() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (!isValid(a)) {
return -1;
}
// Special case for n=2 and both numbers are 60
if (n == 2 && a[0] == 60 && a[1] == 60) {
return handle_60_60_case();
}
// For single number
if (n == 1) {
if (a[0] == 0) return 0;
if (a[0] == 60) return (1LL << 60) - 1;
ll result = (1LL << a[0]) - 1;
return result;
}
// For normal sequences
for (ll start = 0; start < (1LL << 16); start++) {
if (countBits(start) != a[0]) continue;
bool valid = true;
for (int i = 1; i < n && valid; i++) {
if (countBits(start + i) != a[i]) {
valid = false;
}
}
if (valid) {
return start;
}
}
return -1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
cout << solve_case() << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
4 5 3 3 4 1 2 3 2 1 2 2 60 60 2 8 0
output:
13 3 2305843009213693949 -1
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 16ms
memory: 5248kb
input:
1 500000 9 9 10 9 10 10 11 8 9 9 10 9 10 10 11 9 10 10 11 10 11 11 12 8 9 9 10 9 10 10 11 9 10 10 11 10 11 11 12 9 10 10 11 10 11 11 12 10 11 11 12 11 12 12 13 3 4 4 5 4 5 5 6 4 5 5 6 5 6 6 7 4 5 5 6 5 6 6 7 5 6 6 7 6 7 7 8 4 5 5 6 5 6 6 7 5 6 6 7 6 7 7 8 5 6 6 7 6 7 7 8 6 7 7 8 7 8 8 9 4 5 5 6 5 6 ...
output:
-1
result:
wrong answer 1st lines differ - expected: '100297', found: '-1'