fork download
  1. /* ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⣰⣿⣿⣿⡟⠁⠀⣠⣾⣿⣿⣿⣿⡿⠟⣿⣿⣿⣿⣿⡿⠿⠛⠛⠉⠉⠙⠛⠻⠿⣿⣿⣿⣿⣿⣿⣶⣤⣀⡀⠀⠀⠀⠹⣿⣿
  2.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⠀⢰⣿⣿⣿⡏⠀⠀⣼⣿⣿⣿⣿⠟⠉⣠⣾⣿⠿⠛⣉⣀⣤⣤⣴⣶⣶⣶⣶⣶⣤⣀⡀⠉⠙⠻⣿⣿⣿⣿⣿⣿⣄⡀⠀⠀⠈⠛
  3.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠈⣿⣿⣿⡇⠀⣼⣿⣿⣿⡿⢃⣤⣾⣿⣫⣵⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣶⣤⡤⠄
  4.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠘⣿⣿⡇⢰⣿⣿⣿⡿⠾⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣦⠀⠀⢻⣿⣿⣿⣿⣧⡀⠀⠀⠀
  5.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⣼⣦⡘⣿⣧⡿⢻⠙⠉⠀⢀⣀⣴⣿⣿⡿⠉⠀⠀⠉⠉⠙⠻⣿⣎⢿⣿⣿⣿⣿⣧⠙⣿⣟⢿⣧⡀⠀⢻⣿⣿⣿⣿⣿⣦⡀⠀
  6.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⡻⢋⣾⠚⠋⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣀⠀⠀⠀⠀⣀⣴⣾⣿⠿⡌⢿⣿⣿⣿⣿⣧⠘⢿⡄⠉⠻⣄⠀⢻⣿⣏⠛⠛⠻⢿⣄
  7.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⣿⠟⠀⠀⠀⠀⠀⠀⠐⠉⠀⢹⣿⣿⣿⣤⣤⣴⣾⣿⣿⣿⠁⠀⠛⠜⣿⣿⣿⣿⣿⣧⠈⢿⡄⢠⠈⠃⠀⠻⣿⣧⡀⠀⠀⣈
  8.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⡿⠿⠛⢻⣷⣶⣿⣿⡘⣿⣿⠹⣿⣿⠀⠈⢿⣄⢳⣤⡀⠀⠙⠛⠿⣆⠀⠘
  9.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⣾⣿⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⢻⡿⠛⠉⠉⣀⡀⠠⠄⠀⠀⠙⠿⣇⢹⣿⡇⢻⡟⢸⡀⠈⢿⣮⣿⣿⣶⣦⣄⣀⣀⣀⣀
  10.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣫⣾⣿⡟⠀⠀⠀⠀⠀⠀⠀⢀⠟⢻⡿⠁⠀⢀⡤⠚⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⢰⣿⣿⠈⢁⣿⡇⠀⣾⣿⣿⣿⣿⣿⣿⣿⡿⠟⣉
  11.   ⢸⣿⣿⣿⣿⣿⣿⣿⣛⣩⠾⠿⠿⠿⢿⡕⢆⠀⠀⠀⠀⠀⠊⠀⠈⠀⣠⠔⣋⣠⣤⣄⣉⣀⡀⠀⠀⠀⠀⠀⢈⣾⣿⣿⡆⣼⣿⠇⠰⣿⣿⣿⣟⠛⢛⣉⣡⣴⣾⣿
  12.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⡿⣄⣧⡀⠀⢠⠀⠑⢤⠴⢋⠁⡾⢻⡿⣿⣿⣯⠛⠛⠲⠤⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⢠⠄⠈⢻⣿⣿⣆⠘⢿⣿⣿⠛⠉
  13.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣹⣿⢿⡃⣿⣦⡀⠀⠀⠀⠀⠀⢠⠇⣿⣇⢀⣿⣿⡇⠀⠀⠀⠀⣀⣾⣿⣿⣿⣿⣿⣿⠇⠀⡀⢄⠀⠩⠻⢿⣷⡌⠻⢿⣧⠀
  14.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢸⣗⢻⣼⣯⠄⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⡿⠃⠀⠀⠀⢠⣾⣿⣿⣿⠿⢋⣿⠟⠀⠑⠈⠀⠁⡀⠀⣼⣿⣿⣶⣤⣽⣇
  15.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣼⣿⡥⠙⠟⠄⠀⠀⠀⠀⠀⠀⠀⠀⣉⠩⠔⠀⠀⢀⣼⠿⠟⠋⠁⠀⠀⣸⠏⠀⡀⠄⠠⠁⠌⠀⣰⣿⣿⡿⣱⣷⣿⡻
  16.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣋⣐⣿⢯⡇⠩⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠉⠁⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⣤⠀⠀⢀⣾⣿⣿⣿⠳⠿⣿⣿⡿
  17.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⡇⢀⣶⣿⣿⣿⣿⣿⣶⣤⡤⠄⣠
  18.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡆⠢⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠋⠀⠇⠘⠛⣿⣿⣿⣿⡿⢛⣩⣴⣾⣿
  19.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⢀⣔⠂⠈⢑⡇⠿⣿⣿⣿⣷⡘⢿⣿⣿⣿
  20.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡈⠁⠀⠀⠀⠉⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠐⠰⢶⡃⣔⣼⡅⢁⠜⠙⣛⣻⢿⣮⣛⣿⣿
  21.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣤⠀⠛⠿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠔⠀⠀⢀⠀⠀⣳⢻⢸⡼⡦⢁⣴⣾⣿⣿⣧⡻⣿⣿⣿
  22.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⠞⠁⠀⠀⠄⠀⣈⡄⡟⠛⠈⠋⠁⣿⣿⣿⣿⣿⣿⣿⣮⣻⣿
  23.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⢤⡀⣐⠶⠿⠟⠁⢂⣀⠤⠴⠒⠉⣁⡄⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣷⣝
  24.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣁⡠⡐⣄⡇⢰⠂⠉⠉⢀⣀⣤⣴⣶⣿⣿⡧⠀⠀⠐⣀⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  25.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣯⣾⣿⡘⣵⠈⡆⠰⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  26.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⣽⣶⣶⣿⡿⣿⣿⣿⡇⡟⡀⡇⠀⣿⣿⣿⣿⣿⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠉
  27.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⠁⠀⠔⠛⠛⠉⠉⠁⣰⣿⣿⣿⣿⣃⣇⠠⠀⣽⣿⣿⣿⠃⠀⠀⠙⠛⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠀⠀
  28.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢁⣤⡾⠃⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⡿⠛⢻⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠻⠿⣿⣿⣿⡿⠃⠀⠀⠀
  29.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢏⣶⣿⣿⠃⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⠁⠀⠀⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢻⣥⡀⠀⠀⠀
  30.   ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢏⣾⣿⣿⡏⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⠀⠀⠀⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣷⡀⠀ */
  31. /*I love CatTuong*/
  32. #include <bits/stdc++.h>
  33. #define ll long long
  34. #define ull unsigned long long
  35. #define pb push_back
  36. #define pf push_front
  37. #define pii pair<int,int>
  38. #define fi first
  39. #define se second
  40. #define IN endl
  41. #define CT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  42. #define BIT(x, i) (((x) >> (i)) & 1)
  43. #define all(x) (x).begin(), (x).end()
  44. #define MASK(i) (1LL << (i))
  45. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  46.  
  47. using namespace std;
  48.  
  49. const int MAX = 100;
  50. ull comb[MAX + 1][MAX + 1];
  51.  
  52. void pre() {
  53. for (int i = 0; i <= MAX; ++i) {
  54. comb[i][0] = comb[i][i] = 1;
  55. for (int j = 1; j < i; ++j) {
  56. comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
  57. }
  58. }
  59. }
  60.  
  61. string solve(int m, int n, int p, ull k) {
  62. int ttl = m + n + p;
  63. string ans = "";
  64.  
  65. while (ttl > 0) {
  66. if (m > 0) {
  67. ull countX = comb[ttl - 1][m - 1] * comb[n + p][p];
  68. if (k <= countX) {
  69. ans += 'X';
  70. --m;
  71. } else {
  72. k -= countX;
  73. if (n > 0) {
  74. ull countY = comb[ttl - 1][m] * comb[n + p - 1][p];
  75. if (k <= countY) {
  76. ans += 'Y';
  77. --n;
  78. } else {
  79. k -= countY;
  80. ans += 'Z';
  81. --p;
  82. }
  83. } else {
  84. ans += 'Z';
  85. --p;
  86. }
  87. }
  88. } else if (n > 0) {
  89. ull countY = comb[ttl - 1][n - 1] * comb[m + p][p];
  90. if (k <= countY) {
  91. ans += 'Y';
  92. --n;
  93. } else {
  94. k -= countY;
  95. ans += 'Z';
  96. --p;
  97. }
  98. } else {
  99. ans += 'Z';
  100. --p;
  101. }
  102. --ttl;
  103. }
  104.  
  105. return ans;
  106. }
  107.  
  108. int main() {
  109. CT
  110. pre();
  111. int m, n, p;
  112. cin >> m >> n >> p;
  113. int Q;
  114. cin >> Q;
  115. vector<ull> q(Q);
  116. for (int i = 0; i < Q; ++i) {
  117. cin >> q[i];
  118. }
  119.  
  120. for (int i = 0; i < Q; ++i) {
  121. cout << solve(m, n, p, q[i]) << IN;
  122. }
  123. cout<<IN;
  124. cerr<<"Time elapsed: "<<TIME<<".s"<<IN;
  125. return 0;
  126. }
  127.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty