QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549348 | #9229. Juliet Unifies Ones | Amanicus# | AC ✓ | 0ms | 3824kb | C++14 | 1.1kb | 2024-09-06 14:38:28 | 2024-09-06 14:38:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll =long long ;
vector<ll>a1,a0;
ll b1[100],b0[100];
ll dp1[100][5],dp2[100][5];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
string s;
cin>>s;
ll n=s.size();
ll f=0;
for(ll i=0;i<n;i++)
{
if(s[i]=='1')
{
f=1;
ll j;
for(j=i;j<n;j++)
{
if(s[j]!=s[i])
{
break;
}
}
a1.push_back(j-i);
i=j-1;
}
else if(s[i]=='0'&&f==1)
{
ll j;
for(j=i;j<n;j++)
{
if(s[j]!=s[i])
{
break;
}
}
a1.push_back(j-i);
i=j-1;
}
}
ll l1=a1.size(),ff=0,ans1=0,ans2=0,i,sum=1e9;
a1.push_back(0);
a1.push_back(0);
if(l1%2==0&&l1!=0)
{
a1[l1-1]=0;
l1--;
}
ans1=0;
for(i=0;i<l1;i+=2)
{
ll j;
for(j=i;j<l1;j+=2)
{
dp1[j+1][0]=dp1[j-1][0]+a1[j+1];
dp1[j+1][1]=min(dp1[j-1][1],dp1[j-1][0])+a1[j+2];
}
sum=min(sum,min(dp1[j-1][0],dp1[j-1][1])+ans1);
for(j=i;j<l1;j+=2)
dp1[j+1][0]=0,dp1[j+1][1]=0;
ans1+=a1[i];
}
if(a1[0]==0)
sum=0;
cout<<sum<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
11101111111111111101001011110111111110011101010110
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
00000000100000000000100000010001000
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
00000000000000000000000000000000000000000000000000
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
00000000100000000000100000011000
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
11000010100100000011101100000001000100000000000000
output:
8
result:
ok 1 number(s): "8"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
01100100111011110101010110000100001111110001110001
output:
19
result:
ok 1 number(s): "19"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1110101111001
output:
3
result:
ok 1 number(s): "3"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
1
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1001
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
11111111111111111111111111111111111111111111111111
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
11111100000000001101010101100011
output:
9
result:
ok 1 number(s): "9"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
11011
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
100011011
output:
2
result:
ok 1 number(s): "2"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
0
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1010101010011011001101100110011101101011100110110
output:
19
result:
ok 1 number(s): "19"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
01110100000000111100000011000000000110010001110101
output:
14
result:
ok 1 number(s): "14"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
01100001000000010000000000010010000100100101001000
output:
9
result:
ok 1 number(s): "9"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
1101010101010101010101010101010101010101010101011
output:
23
result:
ok 1 number(s): "23"
Extra Test:
score: 0
Extra Test Passed