fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main()
  5. {
  6. int n, m, code_count = 0;
  7. std::cin >> n >> m;
  8. std::string code(n, '0');
  9. code[n - 1] = '1';
  10. for (int i = 1; i < m && code_count < m; ++i)
  11. {
  12. while (next_permutation(code.end() - i, code.end()) && code_count < m)
  13. ++code_count;
  14. code[code.size() - i - 1] = '1';
  15. ++code_count;
  16. }
  17. std::cout << code;
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 4248KB
stdin
Standard input is empty
stdout
Standard output is empty