QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#169124 | #7109. Traveling on the Axis | LilyWhite# | AC ✓ | 4ms | 5612kb | C++14 | 2.1kb | 2023-09-09 12:46:24 | 2023-09-09 12:46:25 |
Judging History
answer
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repr(i, m, n) for (int i = (int)m; i <= (int)n; i++)
#define repd(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#ifdef LILYWHITE
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) ;
#endif
const int __attribute__((unused)) INF = 0x3f3f3f3f;
template <typename T> inline T rd(T &x) {
x = 0;
T neg = 1;
char c = 0;
while (c < '0' || c > '9') {
if (c == '-')
neg = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - 48;
c = getchar();
}
x *= neg;
return x;
}
template <typename T, typename... Args> inline void rd(T &x, Args &...args) {
rd(x);
rd(args...);
}
#define MAXN 100100
char s[MAXN];
long long T, n, cnt0[MAXN], cnt1[MAXN], ans;
int main() {
scanf("%lld",&T);
while(T--)
{
scanf("%s",s+1);
n = strlen(s+1);
ans = 0;
for(ll i=0;i<=n;i++) cnt0[i] = cnt1[i] = 0;
for(ll i=0;i<=n-1;i++)
{
cnt0[i]++;
if(s[i+1] == '1')
{
cnt1[i+1] = cnt0[i]+cnt1[i];
ans = ans + cnt0[i] * (n-i) + cnt1[i] * (n-i) * 2;
}
else
{
cnt0[i+1] = cnt0[i]+cnt1[i];
ans = ans + cnt0[i] * (n-i) * 2 + cnt1[i] * (n-i);
}
}
printf("%lld\n",ans);
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3952kb
input:
3 101 011 11010
output:
12 15 43
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 4ms
memory: 5612kb
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