QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#722594 | #9229. Juliet Unifies Ones | hoshinomiyako | WA | 0ms | 1608kb | C++14 | 1.5kb | 2024-11-07 19:37:53 | 2024-11-07 19:37:54 |
Judging History
answer
#include <cstdio>
#include <cstring>
using namespace std;
char s[100];
int t[100];
int f0[100];
int f1[100];
int b0[100];
int b1[100];
int min(int a,int b){return a>b?b:a;}
int main()
{
int p=0,as=0,cnt=0,n=0,ll=0,tas=0;
scanf("%s",s);
ll=strlen(s);
while(s[p]=='0'&&p<ll)++p;
cnt=1;
++p;
for(;p<ll;++p){
if(s[p]==s[p-1])++cnt;
else{
t[n++]=cnt;
cnt=1;
}
}
t[n++]=cnt;
if(s[ll-1]=='0')--n;
// for(int i=0;i<n;++i)printf("%d ",t[i]);
// printf("\n");
tas=0;
for(int i=1;i<n;i+=2)tas+=t[i];
as=tas;
// printf("tas=%d\n",tas);
// printf("debug n=%d\n",n);
f1[1]=t[0];
for(int i=3;i<n;i+=2)f1[i]=f1[i-2]+t[i-1];
// printf("debug 1\n");
f0[1]=t[1];
for(int i=3;i<n;i+=2)f0[i]=f0[i-2]+t[i];
// printf("debug 2\n");
for(int i=n-2;i>0;i-=2)b1[i]=b1[i+2]+t[i+1];
// printf("debug 3\n");
for(int i=n-2;i>0;i-=2)b0[i]=b0[i+2]+t[i];
// printf("debug 4\n");
// for(int i=1;i<n;i+=2)printf("i=%d f0=%d f1=%d b0=%d b1=%d\n",i,f0[i],f1[i],b0[i],b1[0]);
for(int i=1;i<n;i+=2)as=min(as,tas-b0[i]+b1[i]);
for(int i=1;i<n;i+=2){
as=min(as,tas-f0[i]+f1[i]);
for(int j=i+1;j<n;j+=2){
as=min(as,tas-f0[i]+f1[i]-b0[j]+b1[j]);
}
}
printf("%d\n",as);
return 0;
}
/*
00011011001
000111100011000
111111
000
1100101010101011
*/
/*
00000000100000000000100000010001000
*/
/*
100000000000100000011
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1588kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1536kb
input:
11101111111111111101001011110111111110011101010110
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1536kb
input:
00000000100000000000100000010001000
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 1524kb
input:
00000000000000000000000000000000000000000000000000
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 1608kb
input:
00000000100000000000100000011000
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 1592kb
input:
11000010100100000011101100000001000100000000000000
output:
10
result:
wrong answer 1st numbers differ - expected: '8', found: '10'