QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#160084 | #7109. Traveling on the Axis | ucup-team1412# | WA | 213ms | 5008kb | C++11 | 1.5kb | 2023-09-02 19:25:29 | 2023-09-02 19:25:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t,n;
int steps[100000+5];
long long houzhui[100000+5];
long long ans;
string s;
int len;
int pos,ti,cnt;
int main()
{
cin>>t;
while(t--)
{
memset(steps,0,sizeof(steps));
memset(houzhui,0,sizeof(houzhui));
ans=0;
pos=0;
ti=0;
cin>>s;
len=s.length();
while(pos<=len)
{
int flag;
if(ti%2)flag=1-(s[pos]-'0');
else flag=s[pos]-'0';
//cout<<"pos="<<pos<<" ti="<<ti<<" flag="<<flag<<" s[pos]="<<s[pos]<<endl;
//system("pause");
if(flag==1)
{
pos++;ti++;
steps[pos]=ti;
if(pos==len)break;
}
else
ti++;
}
houzhui[len]=steps[len];
for(int i=len-1;i>=0;i--)
{
ans+=steps[i+1];
houzhui[i]=houzhui[i+1]+steps[i];
}
/*
for(int i=0;i<=len;i++)
cout<<steps[i]<<" ";
cout<<endl;
for(int i=0;i<=len;i++)
cout<<houzhui[i]<<" ";
cout<<endl;
*/
for(int i=1;i<len;i++)
{
int ifchanged;
if(steps[i]%2==1)ifchanged=1;
else ifchanged=0;
if(!ifchanged)
{
ans+=houzhui[i+1]-(len-i)*steps[i];
}
else
{
if(s[i]=='0')
{
ans+=houzhui[i+1]-(len-i)*steps[i];
ans+=(len-i);
}
else
{
i++;
ans+=houzhui[i+1]-(len-i)*steps[i];
ans+=(len-i+1);
i--;
}
}
}
cout<<ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4876kb
input:
3 101 011 11010
output:
12 15 43
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 213ms
memory: 5008kb
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:
wrong answer 6102nd lines differ - expected: '151538662672591', found: '272892963621071'