# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
894918 | LeonaRaging | Flip it and Stick it (CCO23_day2problem1) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb emplace_back
#define pf emplace_front
#define fi first
#define se second
#define T pair<int,int>
#define all(val) val.begin(), val.end()
#define SZ(val) (int)val.size()
#define db(val) "[" #val " = " << (val) << "] "
const int maxn = 3e5 + 4;
const int N = 16;
const int mod = 1e9 + 7;
const int INF = 1e9;
void coding() {
if (fopen("inputf.in", "r")) {
freopen("inputf.in", "r", stdin);
freopen("outputf.out", "w", stdout);
freopen("log.out", "w", stderr);
}
if (fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
}
string s, t;
namespace sub1 {
void Solve() {
bool f = 0;
for (int i = 0; i < SZ(s); i++)
if (s[i] == '0')
return cout << -1, void();
cout << 0;
}
}
namespace sub2 {
void Solve() {
int res = 0;
for (int i = 0; i < SZ(s) - 1; i++)
if (s[i] == '0' && s[i + 1] == '1')
res++;
cout << res;
}
}
namespace sub3 {
void Solve() {
int cnt0 = 0, cnt1 = 0, res = 0;
for (int i = 0; i < SZ(s); i++) {
if (s[i] == '0') cnt0++;
else cnt1++;
if (i < SZ(s) - 1 && s[i] == '0' && s[i + 1] == '0') res++;
}
if (cnt0 > cnt1 + 1) return cout << -1, 0;
cout << res;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
coding();
cin >> s >> t;
if (t[0] == '1') {
for (int i = 0; i < SZ(t); i++)
if (t[i] == '0') t[i] = '1';
else t[i] = '0';
for (int i = 0; i < SZ(s); i++)
if (s[i] == '0') s[i] = '1';
else s[i] = '0';
}
if (t == "0") sub1::Solve();
if (t == "01") sub2::Solve();
if (t == "00") sub3::Solve();
}