QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601553 | #5075. Fenwick Tree | gozonite | WA | 79ms | 3608kb | C++14 | 1.3kb | 2024-09-30 07:01:35 | 2024-09-30 07:01:35 |
Judging History
answer
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <deque>
#include <queue>
#include <tuple>
#include <cmath>
#include <cctype>
#include <stack>
#include <cassert>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
using ll = long long;
int n;
int c[100001];
int main() {
// freopen("L.in", "r", stdin);
// freopen("L.out", "w", stdout);
int T; cin >> T;
while (T--) {
cin >> n;
string s; cin >> s; s = " " + s;
for (int i = 1; i <= n; i++) c[i] = s[i]-'0';
int ans = 0;
for (int i = 1; i <= n; i++) {
if (i%2 == 1) { ans += (c[i]==1); continue; }
int pwr = i&-i;
int j = i-pwr;
int zc = 0, oc = 0;
while (pwr % 2 == 0) {
pwr >>= 1;
j += pwr;
if (c[j] == 0) zc++;
else oc++;
}
if (zc == oc) continue;
if (c[i] == 1 && oc == 0) ans++;
else if (c[i] == 0 && oc == 1) ans++;
}
cout << ans << endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
3 5 10110 5 00000 5 11111
output:
3 0 3
result:
ok 3 number(s): "3 0 3"
Test #2:
score: -100
Wrong Answer
time: 79ms
memory: 3496kb
input:
100000 10 0000000000 10 0000000100 10 0000000000 10 1000000000 10 0000010000 10 0000000000 10 0000000000 10 0000000000 10 0100000000 10 0000000000 10 0000000001 10 0000001000 10 0000000000 10 0000000000 10 0000000001 10 0000100000 10 0010000000 10 0000000000 10 0010000000 10 0000000001 10 0000000000...
output:
0 1 0 2 2 0 0 0 1 0 1 2 0 0 1 2 1 0 1 1 0 0 2 2 1 0 2 2 1 0 2 2 0 0 2 2 0 0 2 0 1 1 0 0 0 0 0 0 0 2 2 1 2 0 1 0 2 2 0 2 1 0 2 2 0 1 0 2 0 0 1 1 0 0 0 1 1 0 2 0 0 0 0 2 2 0 0 0 0 0 0 2 0 2 2 0 2 2 2 0 0 0 0 0 0 0 1 0 0 0 2 0 2 0 0 0 2 0 1 0 0 2 0 0 0 1 0 0 1 2 0 0 2 0 1 0 0 2 0 2 0 0 0 1 0 0 1 1 1 0 ...
result:
wrong answer 9th numbers differ - expected: '2', found: '1'