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;
int Count(string S, string T) {
int ret = 0;
for (int i = 0; i + T.size() <= S.size(); ++i) {
ret += (S.substr(i, T.size()) == T);
}
return ret;
}
int Solve(string S, string T) {
if (T.size() == 1) return (S.find(T) == string::npos ? 0 : -1);
if (T == "011" || T == "100") {
reverse(S.begin(), S.end());
reverse(T.begin(), T.end());
}
if (T[0] == '1') {
for (char& c : S) c ^= 1;
for (char& c : T) c ^= 1;
}
int zero = 0;
for (char c : S) zero += (c == '0');
if (T == "01") return Count(S, T);
if (T == "00") {
int lim = (S.size() + 1) / 2;
if (lim < zero) return -1;
return Count(S, T);
}
if (T == "001") return Count(S, T);
if (T == "010") return (Count(S, T) + 1) / 2;
if (T == "000") {
int lim = (int)S.size() - (int)S.size() / 3;
if (lim < zero) return -1;
return Count(S, T);
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
string S, T;
cin >> S >> T;
cout << Solve(S, T);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int Solve(std::string, std::string)':
Main.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
41 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |