QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549391 | #9229. Juliet Unifies Ones | clearlove13# | AC ✓ | 0ms | 3812kb | C++23 | 2.2kb | 2024-09-06 15:04:48 | 2024-09-06 15:04:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ull = unsigned long long;
#define ff(x) fixed << setprecision(x)
#define vel vector<long long>
#define vei vector<int>
#define ves vector<string>
#define asn ans
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr db EPS = 1.0e-9;
constexpr ll MOD = 998244353LL;
constexpr ll SZ = 1e6;
constexpr ll MAXN5 = 2e5 + 5;
constexpr ll MAXN6 = 2e6 + 5;
ll n, m;
void Solve(void) {
string s;
while (cin >> s) {
ll a[s.size() + 1];
fill(a, a + s.size() + 1, 0);
vector<int> xia;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
a[i + 1] = 1;
xia.push_back(i + 1);
}
}
for (int i = 1; i <= s.size(); i++) {
a[i] += a[i - 1];
}
int ans = min({s.size() - xia.size(), xia.size()});
if (xia.size() <= 1) {
cout << ans << '\n';
continue;
}
int lenz = 1;
int count1 = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] == s[i - 1] && s[i] == '1') {
count1++;
lenz = max(lenz, count1+1);
} else {
count1 = 0;
}
}
// for(auto x:xia){
// cout<<x<< ' ' ;
// cout<<a[x]<<'\n';
// }
for (int i = 0; i < xia.size(); i++) {
for (int j = i + 1; j < xia.size(); j++) {
int zuo = a[xia[i] - 1] - a[0];
int you = a[s.size()] - a[xia[j]];
int mid = xia[j] - xia[i] + 1 + a[xia[i] - 1] - a[xia[j]];
// cout << zuo << ' ' << you << ' ' << mid << '\n';
ans = min({ans, zuo + you + mid, (int)s.size()});
}
}
cout << min(ans, (int)xia.size() - lenz) << '\n';
}
}
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
// freopen("mine.in", "r", stdin);
// freopen("mine.out", "w", stdout);
int cas = 1;
// cin >> cas;
while (cas--)
Solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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: 3524kb
input:
00000000100000000000100000010001000
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
00000000000000000000000000000000000000000000000000
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
00000000100000000000100000011000
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
11000010100100000011101100000001000100000000000000
output:
8
result:
ok 1 number(s): "8"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
01100100111011110101010110000100001111110001110001
output:
19
result:
ok 1 number(s): "19"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1110101111001
output:
3
result:
ok 1 number(s): "3"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
1001
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
11111111111111111111111111111111111111111111111111
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
11111100000000001101010101100011
output:
9
result:
ok 1 number(s): "9"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
11011
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
100011011
output:
2
result:
ok 1 number(s): "2"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
0
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
1010101010011011001101100110011101101011100110110
output:
19
result:
ok 1 number(s): "19"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
01110100000000111100000011000000000110010001110101
output:
14
result:
ok 1 number(s): "14"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
01100001000000010000000000010010000100100101001000
output:
9
result:
ok 1 number(s): "9"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
1101010101010101010101010101010101010101010101011
output:
23
result:
ok 1 number(s): "23"
Extra Test:
score: 0
Extra Test Passed