QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#529819#9229. Juliet Unifies Onesucup-team3712#AC ✓0ms3820kbC++201.4kb2024-08-24 14:05:552024-08-24 14:05:55

Judging History

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

  • [2024-08-24 14:05:55]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3820kb
  • [2024-08-24 14:05:55]
  • 提交

answer

//created: 2024-08-24 13:04:14
#if defined(YUANSHEN)
#include<D:/Tovi/template/my_template.hpp>
#else
#include<bits/stdc++.h>
using namespace std;
#define dbg(...) 42
#endif
template <typename T1, typename T2> void cmin(T1 &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T1, typename T2> void cmax(T1 &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define fixset(x) fixed<<setprecision(x)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define ALL(x) (x).begin()+1,(x).end()
const int INF = 1000000000;
const ll LNF = 1000000000000000000;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int st=s.find('1'),ed;
    if(st==-1){
        cout<<"0\n";
        return 0;
    }
    for(int i=sz(s)-1;i>=0;i--){
        if(s[i]=='1'){
            ed=i;
            break;
        }
    }
    //001110011001100
    // int ans=count(s.begin()+st,s.begin()+ed+1,'0');
    // dbg(st,ed,ans);
    int ans=INF;
    auto calc=[&](int l,int r){
        int res=count(s.begin()+l,s.begin()+r+1,'0');
        res+=count(all(s),'1')-(r-l+1-res);
        // dbg(res);
        return res;
    };
    for(int l=st;l<=ed;l++){
        for(int r=l;r<=ed;r++){
            cmin(ans,calc(l,r));
        }
    }
    cout<<ans<<'\n';
    return 0;
}

详细

Test #1:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

11101111111111111101001011110111111110011101010110

output:

11

result:

ok 1 number(s): "11"

Test #3:

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

input:

00000000100000000000100000010001000

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

input:

00000000000000000000000000000000000000000000000000

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

00000000100000000000100000011000

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

11000010100100000011101100000001000100000000000000

output:

8

result:

ok 1 number(s): "8"

Test #7:

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

input:

01100100111011110101010110000100001111110001110001

output:

19

result:

ok 1 number(s): "19"

Test #8:

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

input:

1110101111001

output:

3

result:

ok 1 number(s): "3"

Test #9:

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

input:

1

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

1001

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

11111111111111111111111111111111111111111111111111

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

11111100000000001101010101100011

output:

9

result:

ok 1 number(s): "9"

Test #13:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #14:

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

input:

11011

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

100011011

output:

2

result:

ok 1 number(s): "2"

Test #16:

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

input:

0

output:

0

result:

ok 1 number(s): "0"

Test #17:

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

input:

1010101010011011001101100110011101101011100110110

output:

19

result:

ok 1 number(s): "19"

Test #18:

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

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: 3612kb

input:

1101010101010101010101010101010101010101010101011

output:

23

result:

ok 1 number(s): "23"

Extra Test:

score: 0
Extra Test Passed