Submission #1128525

#TimeUsernameProblemLanguageResultExecution timeMemory
1128525nhanhoang510Flip it and Stick it (CCO23_day2problem1)C++20
9 / 25
2 ms1488 KiB
#include <bits/stdc++.h> #define F first #define S second using namespace std; const int maxn = 2 * 1e5 + 7; const int LOG = 20; const long long MOD = (long long)(1e9) + 7; const long long base = 311; const int ALP_BET = 26; typedef pair<int, int> ii; typedef pair<int, long long> il; typedef pair<long long, int> li; typedef pair<long long, long long> ll; string s; int n, a[maxn]; int m, b[maxn]; namespace SUB1{ void solve(){ bool ok = true; for(int i = 1; i <= n; ++i) if(a[i] == b[m]) ok = false; if(!ok) cout << -1 << "\n"; else cout << 0 << "\n"; return; } } namespace SUB2{ void solve(){ bool ok = true; for(int i = 1; i < n; ++i) if(a[i] == b[1] && a[i + 1] == b[2]){ ok = false; break; } if(ok){ cout << 0 << "\n"; return; } int num[2] = {0, 0}; for(int i = 1; i <= n; ++i){ num[a[i]]++; while(i < n && a[i] == a[i + 1]) ++i; } swap(b[1], b[2]); if(b[1] == a[1]){ cout << num[b[1]] - 1 << "\n"; } else cout << num[b[1]] << "\n"; return; } } namespace SUB3{ void solve(){ int res = 0; for(int i = 1; i < n; ++i) if(a[i] == b[1] && a[i + 1] == b[2]) ++res; cout << res << "\n"; return; } } namespace SUB4{ void solve(){ int res = 0; for(int i = 1; i <= n - 2; ++i){ bool ok = true; for(int j = 1; j <= m; ++j) if(a[i + j - 1] != b[j]){ ok = false; break; } if(ok) ++res; } cout << res << "\n"; return; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s; n = s.size(); for(int i = 1; i <= n; ++i) a[i] = int(s[i - 1]) - int('0'); cin >> s; m = s.size(); for(int i = 1; i <= m; ++i) b[i] = int(s[i - 1]) - int('0'); if(m == 1){ SUB1::solve(); } else if(m == 2 && b[1] != b[2]){ SUB2::solve(); } else if(m == 2){ SUB3::solve(); } else SUB4::solve(); 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...