Submission #1093526

#TimeUsernameProblemLanguageResultExecution timeMemory
1093526IBoryFlip it and Stick it (CCO23_day2problem1)C++17
8 / 25
3 ms1344 KiB
#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[0] == '1') { for (char& c : S) c ^= 1; for (char& c : T) c ^= 1; } if (T == "01") return Count(S, T); if (T == "00") { int lim = (S.size() + 1) / 2, zero = 0; for (char c : S) zero += (c == '0'); if (lim < zero) return -1; return Count(S, T); } return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); string S, T; cin >> S >> T; cout << Solve(S, T); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...