QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#385015 | #6843. PTSD | wandw | WA | 1ms | 3596kb | C++17 | 836b | 2024-04-10 14:43:00 | 2024-04-10 14:43:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
int suf[200005]={};
void solve()
{
int n;
cin>>n;
string s;
cin>>s;
s=" "+s;
suf[n+1]=0;
for(int i=n;i>=1;i--)
{
suf[i]=suf[i+1]+(s[i]=='0');
}
int ans=0;
for(int i=n;i>=1;i--)
{
//suf[i]=suf[i+1];
if(s[i]=='1'&&suf[i+1]==0)
{
suf[i]++;
continue;
}
if(s[i]=='1'&&suf[i+1]>0)
{
ans+=i;
//cout<<"i "<<i<<'\n';
suf[i]=max(suf[i]-1,0ll);
}
}
cout<<ans<<'\n';
}
signed main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
4 5 10101 8 11111111 4 1100 4 0110
output:
4 16 3 3
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
14 1 0 1 1 2 00 2 01 2 10 2 11 3 000 3 001 3 010 3 011 3 100 3 101 3 110 3 111
output:
0 0 0 0 1 1 0 0 2 2 1 1 2 2
result:
ok 14 lines
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3512kb
input:
2046 1 0 1 1 2 00 2 01 2 10 2 11 3 000 3 001 3 010 3 011 3 100 3 101 3 110 3 111 4 0000 4 0001 4 0010 4 0011 4 0100 4 0101 4 0110 4 0111 4 1000 4 1001 4 1010 4 1011 4 1100 4 1101 4 1110 4 1111 5 00000 5 00001 5 00010 5 00011 5 00100 5 00101 5 00110 5 00111 5 01000 5 01001 5 01010 5 01011 5 01100 5 0...
output:
0 0 0 0 1 1 0 0 2 2 1 1 2 2 0 0 3 3 2 2 3 3 1 1 4 4 3 2 4 4 0 0 4 4 3 3 4 4 2 2 6 6 5 3 6 6 1 1 5 5 4 4 5 5 3 3 7 6 6 4 6 6 0 0 5 5 4 4 5 5 3 3 8 8 7 4 8 8 2 2 7 7 6 6 7 7 5 5 10 8 9 6 8 8 1 1 6 6 5 5 6 6 4 4 9 9 8 5 9 9 3 3 8 8 7 7 8 7 6 6 11 9 10 6 9 9 0 0 6 6 5 5 6 6 4 4 10 10 9 5 10 10 3 3 9 9 8...
result:
wrong answer 28th lines differ - expected: '3', found: '2'