fork(3) download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8.  
  9. int main()
  10. {
  11.  
  12. long long t;
  13. cin >> t;
  14.  
  15. while(t--)
  16. {
  17. long long n, x;
  18.  
  19. cin >> x >> n;
  20.  
  21. string ans = "0";
  22.  
  23. for(long long i = 0 ; i <= n ; i++)
  24. {
  25. ans += '0';
  26. }
  27.  
  28. ans[x] = '2';
  29.  
  30. long long s;
  31.  
  32. s = (n * (n + 1))/2 - x;
  33.  
  34. if(s % 2)
  35. {
  36. cout << "impossible" << endl;
  37. goto pg;
  38. }
  39.  
  40.  
  41. s /= 2;
  42.  
  43. for(long long i = n ; i >= 1 ; i--)
  44. {
  45. if(i == x)
  46. continue;
  47.  
  48. if(s >= i && ((s - i) > n))
  49. {
  50. s -= i;
  51. ans[i] = '1';
  52. }
  53.  
  54. else if(s >= i && ((s - i <= n) && ans[s - i] != '2'))
  55. {
  56. s -= i;
  57. ans[i] = '1';
  58. }
  59.  
  60. if(!s)
  61. break;
  62. }
  63.  
  64. if(s > 0)
  65. cout << "impossible";
  66.  
  67. else
  68. for(long long i = 1 ; i <= n ; i++)
  69. cout << ans[i];
  70. cout << endl;
  71.  
  72. pg:;
  73.  
  74. //delete [] hash;
  75. }
  76. }
Time limit exceeded #stdin #stdout 5s 3934936KB
stdin
Standard input is empty
stdout
Standard output is empty