fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define cint(d) scanf("%d", &d)
  9. #define cint2(a, b) scanf("%d %d", &a, &b)
  10. #define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
  11. #define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
  12.  
  13. #define clong(d) scanf("%lld", &d)
  14. #define clong2(a, b) scanf("%lld %lld", &a, &b)
  15. #define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
  16. #define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
  17.  
  18. #define foreach(v, c) for(__typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
  19. #define revforeach(v, c) for(__typeof( (c).rbegin()) v = (c).rbegin(); v != (c).rend(); ++v)
  20. #define ALL(v) (v).begin(), (v).end()
  21.  
  22. #define pb push_back
  23. #define eb emplace_back
  24. #define mp make_pair
  25. #define fi first
  26. #define se second
  27.  
  28. typedef long long int slong;
  29. typedef pair<int, int> pii;
  30. typedef pair<slong, slong> pll;
  31. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  32. typedef set<int>::iterator sit;
  33. typedef map<int,int>::iterator mit;
  34. typedef vector<int>::iterator vit;
  35.  
  36. #ifdef VSP4
  37. #include "debug.h"
  38. #else
  39. #define debug(args...) // Just strip off all debug tokens
  40. #endif
  41.  
  42. const int MOD = 1000000007;
  43. #define MODSET(d) if ((d) >= MOD) d %= MOD;
  44. #define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
  45. #define MODADDSET(d) if ((d) >= MOD) d -= MOD;
  46. #define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;
  47.  
  48. const int MAXN = 100;
  49. const int SQRTN = 550;
  50. const int LOGN = 60;
  51. const int INT_INFINITY = 1001001001;
  52. const int LIMIT = 1e6;
  53.  
  54. const slong LONG_INFINITY = 1001001001001001001ll;
  55. const slong LONG_LIMIT = 200100100100101ll;
  56.  
  57. const double DOUBLE_INFINITY = 1e16;
  58.  
  59. int N, R, O, Y, G, B, V;
  60.  
  61. int main()
  62. {
  63. #ifdef VSP4
  64. freopen("input.txt", "r", stdin);
  65. freopen("output.txt", "w", stdout);
  66. #endif
  67.  
  68. cout.tie(0);
  69. cin.tie(0);
  70.  
  71. int t, T, i, j;
  72.  
  73. cin >> T;
  74.  
  75. for (t = 1; t <= T; t++)
  76. {
  77. cin >> N >> R >> O >> Y >> G >> B >> V;
  78.  
  79. vector<pair<int, char> > data;
  80.  
  81. data.pb(mp(R, 'R'));
  82. data.pb(mp(Y, 'Y'));
  83. data.pb(mp(B, 'B'));
  84.  
  85. sort(ALL(data), greater<pair<int, char> >());
  86.  
  87. cout << "Case #" << t << ": ";
  88.  
  89. if (data[0].fi == 1)
  90. {
  91. for (i = 0; i < 3; i++)
  92. {
  93. if (data[i].fi)
  94. {
  95. cout << data[i].se;
  96. }
  97. }
  98. }
  99. else
  100. {
  101. if (data[0].fi <= (data[1].fi + data[2].fi))
  102. {
  103. vector<pair<int, char> > back = data;
  104.  
  105. int extra = (data[1].fi + data[2].fi) - data[0].fi;
  106.  
  107. int a, b, c;
  108. a = b = c = 0;
  109.  
  110. for (i = 0; i < extra; i++)
  111. {
  112. a++;
  113. b++;
  114. c++;
  115. cout << data[0].se << data[1].se << data[2].se;
  116. }
  117.  
  118. data[1].fi -= extra;
  119. data[2].fi -= extra;
  120.  
  121. for (i = 0; i < data[1].fi; i++)
  122. {
  123. a++;
  124. b++;
  125. cout << data[0].se << data[1].se;
  126. }
  127.  
  128. for (i = 0; i < data[2].fi; i++)
  129. {
  130. a++;
  131. c++;
  132. cout << data[0].se << data[2].se;
  133. }
  134.  
  135. assert(a == back[0].fi);
  136. assert(b == back[1].fi);
  137. assert(c == back[2].fi);
  138. }
  139. else
  140. {
  141. cout << "IMPOSSIBLE";
  142. }
  143. }
  144.  
  145. cout << endl;
  146. }
  147.  
  148. return 0;
  149. }
  150.  
Success #stdin #stdout 0s 16064KB
stdin
2
6 2 0 2 0 2 0
3 1 0 2 0 0 0
stdout
Case #1: YRBYRB
Case #2: IMPOSSIBLE