QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722658#9229. Juliet Unifies OneshoshinomiyakoAC ✓0ms1632kbC++141.5kb2024-11-07 19:50:092024-11-07 19:50:11

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 19:50:11]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:1632kb
  • [2024-11-07 19:50:09]
  • 提交

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);
    f1[1]=t[0];
    for(int i=3;i<n;i+=2)f1[i]=f1[i-2]+t[i-1];
    f0[1]=t[1];
    for(int i=3;i<n;i+=2)f0[i]=f0[i-2]+t[i];
    for(int i=n-2;i>0;i-=2)b1[i]=b1[i+2]+t[i+1];
    for(int i=n-2;i>0;i-=2)b0[i]=b0[i+2]+t[i];
//    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[i]);
    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+2;j<n;j+=2){
            as=min(as,tas-f0[i]+f1[i]-b0[j]+b1[j]);
//            printf("i=%d j=%d f0=%d f1=%d b0=%d b1=%d\n",i,j,f0[i],f1[i],b0[j],b1[j]);
        }
    }
    printf("%d\n",as);
    return 0;
}
/*
00011011001
000111100011000
111111
000
1100101010101011
*/
/*
00000000100000000000100000010001000
*/
/*
100000000000100000011
*/
/*
110000101001000000111011000000010001
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 1536kb

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 1632kb

input:

11101111111111111101001011110111111110011101010110

output:

11

result:

ok 1 number(s): "11"

Test #3:

score: 0
Accepted
time: 0ms
memory: 1544kb

input:

00000000100000000000100000010001000

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 0ms
memory: 1624kb

input:

00000000000000000000000000000000000000000000000000

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 0ms
memory: 1584kb

input:

00000000100000000000100000011000

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: 0
Accepted
time: 0ms
memory: 1528kb

input:

11000010100100000011101100000001000100000000000000

output:

8

result:

ok 1 number(s): "8"

Test #7:

score: 0
Accepted
time: 0ms
memory: 1576kb

input:

01100100111011110101010110000100001111110001110001

output:

19

result:

ok 1 number(s): "19"

Test #8:

score: 0
Accepted
time: 0ms
memory: 1608kb

input:

1110101111001

output:

3

result:

ok 1 number(s): "3"

Test #9:

score: 0
Accepted
time: 0ms
memory: 1584kb

input:

1

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 0ms
memory: 1604kb

input:

1001

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 0ms
memory: 1608kb

input:

11111111111111111111111111111111111111111111111111

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 0ms
memory: 1576kb

input:

11111100000000001101010101100011

output:

9

result:

ok 1 number(s): "9"

Test #13:

score: 0
Accepted
time: 0ms
memory: 1612kb

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #14:

score: 0
Accepted
time: 0ms
memory: 1560kb

input:

11011

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 0ms
memory: 1544kb

input:

100011011

output:

2

result:

ok 1 number(s): "2"

Test #16:

score: 0
Accepted
time: 0ms
memory: 1592kb

input:

0

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 0ms
memory: 1536kb

input:

1010101010011011001101100110011101101011100110110

output:

19

result:

ok 1 number(s): "19"

Test #18:

score: 0
Accepted
time: 0ms
memory: 1584kb

input:

01110100000000111100000011000000000110010001110101

output:

14

result:

ok 1 number(s): "14"

Test #19:

score: 0
Accepted
time: 0ms
memory: 1608kb

input:

01100001000000010000000000010010000100100101001000

output:

9

result:

ok 1 number(s): "9"

Test #20:

score: 0
Accepted
time: 0ms
memory: 1632kb

input:

1101010101010101010101010101010101010101010101011

output:

23

result:

ok 1 number(s): "23"

Extra Test:

score: 0
Extra Test Passed