fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. string solution(vector<int> a, vector<int> b, vector<string> s) {
  6.  
  7. vector<int> an, bn; vector<string> result;
  8.  
  9. for (int i=0; i<a.size(); ++i) {
  10. if (a[i]==b[i])
  11. return s[i];
  12.  
  13. an.push_back(a[i]+1);
  14. bn.push_back(b[i]*2);
  15. result.push_back(s[i]+"1");
  16.  
  17. an.push_back(a[i]*2);
  18. bn.push_back(b[i]+1);
  19. result.push_back(s[i]+"2");
  20. }
  21. return solution(an, bn, result);
  22. }
  23.  
  24. int main() {
  25. vector<int> a(1), b(1);
  26. cin >> a[0] >> b[0];
  27. vector<string> s; s.push_back("");
  28. cout << solution(a, b, s);
  29. return 0;
  30. }
Success #stdin #stdout 0s 15232KB
stdin
2 4
stdout
112122