fork download
  1. // B
  2. #pragma GCC optimize ("O3")
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. using ll = long long;
  6. using db = long double;
  7. const int N = 2e5 + 5, MOD = 1e9 + 7;
  8. using mat = vector<vector<int>>;
  9.  
  10. int main(){
  11. #ifdef ONLINE_JUDGE
  12. ios_base::sync_with_stdio(0);cin.tie(0);
  13. #endif // ONLINE_JUDGE
  14. string a, b;
  15. cin >> a >> b;
  16. int n = a.size();
  17. if((count(a.begin(),a.end(),'1')+count(b.begin(),b.end(),'1')) & 1){
  18. cout << -1 << '\n';
  19. return 0;
  20. }
  21. int ans = INT_MAX;
  22. for(int i = 0; i < n; i++){
  23. vector<int> tmp;
  24. for(int j = 0; j < n; j++)
  25. if(a[j] != b[(i+j)%n])
  26. tmp.push_back(j);
  27. int sum = 0;
  28. for(int j = 0; j < tmp.size(); j += 2)
  29. sum += (tmp[j + 1] - tmp[j]);
  30. ans = min(ans, min(sum, n - sum));
  31. }
  32. cout << ans << '\n';
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
2147483647