QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#535097#9229. Juliet Unifies OnesSocialPandaAC ✓0ms3868kbC++202.3kb2024-08-27 20:02:222024-08-27 20:02:22

Judging History

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

  • [2024-08-27 20:02:22]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3868kb
  • [2024-08-27 20:02:22]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
//#define int long long
//#define LL long long
#define double long double
//#define lf Lf
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define PII pair<int,int>
#define Gheap priority_queue<int,vector<int>,greater<int>>
#define Lheap priority_queue<int>
#define MAXN 0x3f3f3f3f
#define MINN -0x3f3f3f3f
using namespace std;
//const int N=1e6+100,M=2*N;
//int e[N],w[M],h[M],ne[M],idx;

int qz0[100],qz1[100];
int hz0[100],hz1[100];

void solve()
{
	int ans=MAXN;
    string s;cin>>s;

    int pk=-1;
    for(int i=0;i<s.size();i++)
    {
    	if(s[i]=='1') break;
    	pk=i;
    }
    for(int i=0;i<=pk;i++) {s.erase(s.begin());}
    pk=s.size();
    for(int i=s.size()-1;i>=0;i--)
    {
    	if(s[i]=='1') break;
    	pk=i;
    }
    for(int i=s.size()-1;i>=pk;i--) s.erase(s.end()-1);

    for(int i=0;i<s.size();i++)
    {
        qz0[i]=qz0[i-1];
        qz1[i]=qz1[i-1];
        if(s[i]=='0') qz0[i]++;
        else qz1[i]++;
    }
    for(int i=s.size()-1;i>=0;i--)
    {
        hz0[i]=hz0[i+1];
        hz1[i]=hz1[i+1];
        if(s[i]=='0') hz0[i]++;
        else hz1[i]++;
    }

    vector<PII> v;

    int head=0,tail=0;
    for(int i=0;i<s.size();i++)
    {
        if(i==s.size()-1 or (s[i]=='1' and s[i+1]=='0'))
        {
            tail = i;
            //cout<<head<<' '<<tail<<endl;
            v.pb({head,tail});
        }
        if(s[i]=='0' and s[i+1]=='1')
        {
            head=i+1;
        }
    }

    for(int i=0;i<v.size();i++)
    {
        for(int j=i;j<v.size();j++)
        {
            int ll = v[i].fi;
            int rr = v[j].se;

            int zuo0 = qz0[ll-1];
            int zuo1 = qz1[ll-1];
            int you0 = hz0[rr+1];
            int you1 = hz1[rr+1];

            int mid = min(qz0[rr]-qz0[ll-1],qz1[rr]-qz1[ll-1]);
            int num = mid+min(zuo0,zuo1)+min(you0,you1);
            ans=min(ans,num);
        }
    }

    if(ans==MAXN) ans=0;
    cout<<ans<<endl;

}
/*

11011001

1111000111000111010101

*/
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int tt=1;
    //cin >> tt;
    while(tt--) solve();
}

詳細信息

Test #1:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

11101111111111111101001011110111111110011101010110

output:

11

result:

ok 1 number(s): "11"

Test #3:

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

input:

00000000100000000000100000010001000

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

00000000000000000000000000000000000000000000000000

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

00000000100000000000100000011000

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

11000010100100000011101100000001000100000000000000

output:

8

result:

ok 1 number(s): "8"

Test #7:

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

input:

01100100111011110101010110000100001111110001110001

output:

19

result:

ok 1 number(s): "19"

Test #8:

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

input:

1110101111001

output:

3

result:

ok 1 number(s): "3"

Test #9:

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

input:

1

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

1001

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

11111111111111111111111111111111111111111111111111

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

11111100000000001101010101100011

output:

9

result:

ok 1 number(s): "9"

Test #13:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #14:

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

input:

11011

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

100011011

output:

2

result:

ok 1 number(s): "2"

Test #16:

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

input:

0

output:

0

result:

ok 1 number(s): "0"

Test #17:

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

input:

1010101010011011001101100110011101101011100110110

output:

19

result:

ok 1 number(s): "19"

Test #18:

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

input:

01110100000000111100000011000000000110010001110101

output:

14

result:

ok 1 number(s): "14"

Test #19:

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

input:

01100001000000010000000000010010000100100101001000

output:

9

result:

ok 1 number(s): "9"

Test #20:

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

input:

1101010101010101010101010101010101010101010101011

output:

23

result:

ok 1 number(s): "23"

Extra Test:

score: 0
Extra Test Passed