QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#157722 | #7109. Traveling on the Axis | ucup-team859# | AC ✓ | 88ms | 9296kb | C++14 | 2.5kb | 2023-09-02 15:45:40 | 2023-09-02 15:45:41 |
Judging History
answer
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int n = (int)s.size();
vector<vector<ll>> suff_time(n + 1, vector<ll>(2));
std::function<ll(int, int)> Solve = [&](int l, int r) -> ll {
if (l == r) {
return 0;
}
if (l == r - 1) {
return s[l] == '1' ? 1 : 2;
}
int mid = (l + r) / 2;
ll answer = Solve(l, mid) + Solve(mid, r);
vector<ll> cnt(2);
vector<ll> sum(2);
suff_time[mid][0] = 0;
suff_time[mid][1] = 0;
for (int i = mid - 1; i >= l; i--) {
if (s[i] == '1') { // green
suff_time[i][0] = suff_time[i + 1][1] + 1;
suff_time[i][1] = suff_time[i + 1][1] + 2;
} else { // red
suff_time[i][0] = suff_time[i + 1][0] + 2;
suff_time[i][1] = suff_time[i + 1][0] + 1;
}
cnt[suff_time[i][0] % 2]++;
sum[suff_time[i][0] % 2] += suff_time[i][0];
}
vector<ll> t(2);
t[0] = 0;
t[1] = 1;
auto Go = [](ll& t, char x) {
if (x == '1') {
// (i, 0) -> (i + 1, 1) +1
// (i, 1) -> (i + 1, 1) +2
if (t % 2 == 0) {
t++;
} else {
t += 2;
}
} else {
// (i, 0) -> (i + 1, 0) +2
// (i, 1) -> (i + 1, 0) +1
if (t % 2 == 1) {
t++;
} else {
t += 2;
}
}
};
for (int i = mid; i < r; i++) {
Go(t[0], s[i]);
Go(t[1], s[i]);
answer += (t[1] - 1) * cnt[1] + sum[1];
answer += t[0] * cnt[0] + sum[0];
}
return answer;
};
cout << Solve(0, n) << "\n";
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
3 101 011 11010
output:
12 15 43
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 88ms
memory: 9296kb
input:
6107 1010101 010110100110101 1010 1010101010010101010 101011 0101101011010101010 0101101011 11011010101 010 1011010 10110101010101010100 010101010110101 10101010101011 0101010101010101011 00101010011000 1010101010010110110 01010101001010101010 101010101010101 100100101010101010 01 011 0101010100101 ...
output:
96 889 24 1515 69 1567 279 345 14 106 1702 791 621 1447 764 1615 1755 736 1333 6 15 542 44 1689 1515 140 833 497 596 24 1640 694 462 30 425 14 1041 1446 96 504 124 75 560 970 771 945 6 1 321 137 786 720 206 769 46 103 225 74 554 2 100 529 260 207 197 2 197 1041 140 857 207 1 74 1604 41 343 1041 14 1...
result:
ok 6107 lines
Extra Test:
score: 0
Extra Test Passed