QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#631919 | #9229. Juliet Unifies Ones | Cu_OH_2 | WA | 1ms | 3776kb | C++20 | 860b | 2024-10-12 10:58:59 | 2024-10-12 10:59:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
string s;
cin >> s;
int n = s.size();
vector<vector<int>> dp(n, vector<int>(3, n));
dp[0][s[0] - '0'] = 0;
dp[0][!(s[0] - '0')] = 1;
for (int i = 1; i < n; ++i)
{
if (s[i] == '1')
{
dp[i][0] = dp[i - 1][0] + 1;
dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]);
dp[i][2] = min(dp[i - 1][2], dp[i - 1][1]) + 1;
}
else
{
dp[i][0] = dp[i - 1][0];
dp[i][1] = dp[i - 1][1] + 1;
dp[i][2] = min(dp[i - 1][1], dp[i - 1][2]);
}
}
cout << min(dp[n - 1][1], dp[n - 1][2]);
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
//cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3776kb
input:
00011011001
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
11101111111111111101001011110111111110011101010110
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
00000000100000000000100000010001000
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
00000000000000000000000000000000000000000000000000
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'