fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. int main(){
  7.  
  8. ios::sync_with_stdio(false);
  9. cin.tie(0);
  10. int tests;
  11. cin >> tests;
  12. while (tests--)
  13. {
  14. string s, r;
  15. cin >> s >> r;
  16.  
  17. ll n = s.length();
  18.  
  19. ll minLen=0;
  20. ll k=0;
  21. vector<ll> v;
  22. ll count=0;
  23.  
  24. bool flag=true;
  25. bool zinc=true; //couldn't think of a better name. ugh...
  26.  
  27. for(ll i=0; i<n; i++){
  28. if(s[i]!=r[i]){
  29. flag=false;
  30. if(count!=0){
  31. v.push_back(count);
  32. count=0;
  33. }
  34. minLen++;
  35. if(zinc) k++;
  36. zinc=false;
  37. }else{
  38. count++;
  39. zinc=true;
  40. }
  41. }
  42.  
  43. if(flag){
  44. cout << 0 << "\n";
  45.  
  46. }else
  47. {
  48. sort(v.begin(), v.end());
  49.  
  50. ll answer=minLen*k;
  51.  
  52. for(ll i=0; i<v.size(); i++){
  53. k--;
  54. minLen+=v[i];
  55. answer = min(answer, minLen*k);
  56. }
  57.  
  58. cout << answer << "\n";
  59. }
  60.  
  61.  
  62. }
  63.  
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 4368KB
stdin
1
ababa
cbcbc
stdout
5