QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#547136#9229. Juliet Unifies OnesFXLY_awa#AC ✓0ms3912kbC++142.9kb2024-09-04 18:35:412024-09-04 18:35:41

Judging History

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

  • [2024-09-04 18:35:41]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3912kb
  • [2024-09-04 18:35:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

/*****************************************************************   Template Start  **************************************************************************/



/*****************************************************************    Define Start   **************************************************************************/
typedef long long                               ll;
typedef unsigned long long                      ull;
#define int                                     long long
#define itn                                     int
#define endl                                    '\n'
#define Endl                                    endl
#define ednl                                    endl
#define al(a)                                   (a).begin(),(a).end()
#define all(a)                                  (a).begin()+1,(a).end()
#define debug(x)                                {cerr<<"ss:"<<x<<endl;}
#define qdebug(x)                               {cerr<<"ss:";for(auto i:x)cout<<i<<" ";cout<<endl;}
#define lowbit(x)                               (x&-x)
#define vi                                      vector<int>
#define pii                                     pair<int,int>
#define pb                                      push_back
#define fs                                      first
#define sc                                      second


constexpr long long maxlonglong = 9223372036854775807;   //9e18
constexpr int maxint = 2147483647;      //2e9
constexpr int INF = 0x7f7f7f7f; //2139062143
constexpr int M = 1e9 + 7;
constexpr int mod =  998244353;
constexpr int p = 0x1F351F35; // good hash number.
const double pi = acos(-1.0);

mt19937_64 rnd(time(0));
constexpr int N=1231564;



inline void solve(){
    string s;cin>>s;
    int n=s.length();
    vi a(n+1);
    for(int i=1;i<=n;i++)a[i]=s[i-1]-'0';
    vi pr(n+2),la(n+2);
    for(int i=1;i<=n;i++)pr[i]=pr[i-1]+a[i];
    for(itn i=n;i;i--)la[i]=la[i+1]+a[i];
    if(pr[n]==0){
        cout<<0<<endl;
        return;
    }
    int ans=INF;
    for(int i=1;i<=n;i++){
        if(a[i]==1)for(int j=i;j<=n;j++){
            if(a[j]==1){
                int cnt=pr[i-1]+la[j+1];
                for(int k=i;k<=j;k++){
                    if(a[k]==0)cnt++;
                }
                ans=min(ans,cnt);
            }
        }
    }
    cout<<ans<<endl;

    




}





signed main()
{
    //freopen("E:\work tool\code document\data\input.in", "r", stdin);
	//freopen("E:\work tool\code document\data\output.out", "w", stdout);
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);    //关闭同步  如果使用 则不要使用<cstdio>
    // cout << fixed << setprecision(10);
    int T=1;
    // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}



详细

Test #1:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

11101111111111111101001011110111111110011101010110

output:

11

result:

ok 1 number(s): "11"

Test #3:

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

input:

00000000100000000000100000010001000

output:

3

result:

ok 1 number(s): "3"

Test #4:

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

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

input:

11000010100100000011101100000001000100000000000000

output:

8

result:

ok 1 number(s): "8"

Test #7:

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

input:

01100100111011110101010110000100001111110001110001

output:

19

result:

ok 1 number(s): "19"

Test #8:

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

input:

1110101111001

output:

3

result:

ok 1 number(s): "3"

Test #9:

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

input:

1

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

1001

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

11111111111111111111111111111111111111111111111111

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

11111100000000001101010101100011

output:

9

result:

ok 1 number(s): "9"

Test #13:

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

input:

00011011001

output:

2

result:

ok 1 number(s): "2"

Test #14:

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

input:

11011

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

100011011

output:

2

result:

ok 1 number(s): "2"

Test #16:

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

input:

0

output:

0

result:

ok 1 number(s): "0"

Test #17:

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

input:

1010101010011011001101100110011101101011100110110

output:

19

result:

ok 1 number(s): "19"

Test #18:

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

input:

01110100000000111100000011000000000110010001110101

output:

14

result:

ok 1 number(s): "14"

Test #19:

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

input:

01100001000000010000000000010010000100100101001000

output:

9

result:

ok 1 number(s): "9"

Test #20:

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

input:

1101010101010101010101010101010101010101010101011

output:

23

result:

ok 1 number(s): "23"

Extra Test:

score: 0
Extra Test Passed