# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
894918 | LeonaRaging | Flip it and Stick it (CCO23_day2problem1) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}