QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#529615 | #9229. Juliet Unifies Ones | ucup-team3661# | AC ✓ | 0ms | 3844kb | C++20 | 649b | 2024-08-24 13:31:53 | 2024-08-24 13:31:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
int N = s.size();
vector<int> cnt0(N);
vector<int> cnt1(N);
for(int i = 0; i < N; i++){
if(s[i] == '0')cnt0[i]++;
else cnt1[i]++;
if(i == 0)continue;
cnt1[i] += cnt1[i-1];
cnt0[i] += cnt0[i-1];
}
int ans = cnt1[N-1];
for(int i = 0; i < N; i++){
for(int j = i; j < N; j++){
int tmp1 = cnt0[j];
if(i != 0)tmp1 -= cnt0[i-1];
int tmp2 = 0;
if(i != 0)tmp2 += cnt1[i-1];
int tmp3 = 0;
tmp3 += cnt1[N-1];
tmp3 -= cnt1[j];
ans = min(ans , tmp1 + tmp2 + tmp3);
}
}
cout << ans << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
11101111111111111101001011110111111110011101010110
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
00000000100000000000100000010001000
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
00000000000000000000000000000000000000000000000000
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
00000000100000000000100000011000
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
11000010100100000011101100000001000100000000000000
output:
8
result:
ok 1 number(s): "8"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
01100100111011110101010110000100001111110001110001
output:
19
result:
ok 1 number(s): "19"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
1110101111001
output:
3
result:
ok 1 number(s): "3"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
1
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1001
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
11111111111111111111111111111111111111111111111111
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
11111100000000001101010101100011
output:
9
result:
ok 1 number(s): "9"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
11011
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
100011011
output:
2
result:
ok 1 number(s): "2"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
0
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1010101010011011001101100110011101101011100110110
output:
19
result:
ok 1 number(s): "19"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
01110100000000111100000011000000000110010001110101
output:
14
result:
ok 1 number(s): "14"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
01100001000000010000000000010010000100100101001000
output:
9
result:
ok 1 number(s): "9"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1101010101010101010101010101010101010101010101011
output:
23
result:
ok 1 number(s): "23"
Extra Test:
score: 0
Extra Test Passed