Josif_tepe

Untitled

Mar 19th, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. //#include <bits/stdc++.h>
  15. using namespace std;
  16. typedef long long ll;
  17. const ll INF = (1 << 30);
  18. const ll inf = (1LL << 60LL);
  19. const int  maxn = 1e4 + 10;
  20. const ll MOD = 1e9 +  7;
  21. int A, B, C;
  22. int arr[maxn];
  23. int main(int argc, const char * argv[]) {
  24.     ios_base::sync_with_stdio(false);
  25.     //        ifstream  cin("in.txt");
  26.     cin >> A >> B >> C;
  27.     vector<pair<int, int> > even, odd;
  28.     for(int i = 1; i <= A; i ++){
  29.         cin >> arr[i];
  30.     }
  31.     int n = A + B + C;
  32.     arr[0] = 0;
  33.     arr[A + 1] = n + 1;
  34.     for(int i = 1; i <= A + 1; i ++){
  35.          
  36.         int from = arr[i - 1];
  37.         from ++;
  38.         int to = arr[i];
  39.         to --;
  40.          
  41.         if(from > to) continue;
  42.         if((to - from + 1) % 2 == 0){
  43.             even.push_back(make_pair(from, to));
  44.         }
  45.         else{
  46.             odd.push_back(make_pair(from, to));
  47.         }
  48.     }
  49.     string ret = "";
  50.     ret += "/";
  51.     for(int i = 1; i <= n; i ++){
  52.         ret += "_";
  53.     }
  54.     for(int i = 1; i <= A; i ++){
  55.         ret[arr[i]] = 'A';
  56.     }
  57.     for(int i = 0; i < (int)even.size(); i ++){
  58.         int sz = even[i].second - even[i].first + 1;
  59.         sz /= 2;
  60.         if(B >= sz and C >= sz){
  61.             B -= sz;
  62.             C -= sz;
  63.             int F = 0;
  64.             for(int j = even[i].first; j <= even[i].second; j ++){
  65.                 if(F == 0){
  66.                     ret[j] = 'B';
  67.                 }
  68.                 else{
  69.                     ret[j] = 'C';
  70.                 }
  71.                 F ^= 1;
  72.             }
  73.              
  74.         }
  75.         else{
  76.             return 0 * printf("-1\n");
  77.         }
  78.     }
  79.     int sum = 0, sum2 = 0;
  80.     int idx =  -1;
  81.     for(int i = 0; i < (int)odd.size(); i ++){
  82.         int sz = odd[i].second - odd[i].first + 1;
  83.         int mxx = sz / 2 + 1;
  84.         int mnn = sz / 2;
  85.         sum += mxx;
  86.         sum2 += mnn;
  87.         int tmp_B = B;
  88.         int tmp_C = C;
  89.         tmp_B -= sum;
  90.         tmp_C -= sum2;
  91.         if(tmp_B < 0 || tmp_C < 0) continue;
  92.         bool ok = true;
  93.         for(int j = i + 1; j < (int)odd.size(); j ++){
  94.             sz = odd[j].second - odd[j].first + 1;
  95.             mxx = sz / 2 + 1;
  96.             mnn = sz / 2;
  97.             if(tmp_C > tmp_B){
  98.                 tmp_C -= mxx;
  99.                 tmp_B -= mnn;
  100.             }
  101.             else if(tmp_B >= tmp_C){
  102.                 tmp_B -= mxx;
  103.                 tmp_C -= mnn;
  104.             }
  105.             if(tmp_B < 0 or tmp_C < 0){
  106.                 ok = false;
  107.                 break;
  108.             }
  109.         }
  110.         if(ok){
  111.             idx = i;
  112.         }
  113.     }
  114.     for(int i  =0; i <= idx; i ++){
  115.         int sz = odd[i].second - odd[i].first + 1;
  116.         int mxx = sz / 2 + 1;
  117.         int mnn = sz / 2;
  118.         if(B >= mxx and C >= mnn){
  119.             B -= mxx;
  120.             C -= mnn;
  121.             int F = 0;
  122.             for(int j = odd[i].first; j <= odd[i].second; j ++){
  123.                 if(F == 0){
  124.                     ret[j] = 'B';
  125.                 }
  126.                 else{
  127.                     ret[j] = 'C';
  128.                 }
  129.                 F ^= 1;
  130.             }
  131.              
  132.              
  133.         }
  134.     }
  135.     //    cout << idx << endl;
  136.     for(int i = idx + 1; i < (int)odd.size(); i ++){
  137.         int sz = odd[i].second - odd[i].first + 1;
  138.         int mxx = sz / 2 + 1;
  139.         int mnn = sz / 2;
  140.         if(B >= C){
  141.             B -= mxx;
  142.             C -= mnn;
  143.             if(B < 0 or C < 0) return 0 * printf("-1\n");
  144.             int F = 0;
  145.             for(int j = odd[i].first; j <= odd[i].second; j ++){
  146.                 if(F == 0){
  147.                     ret[j] = 'B';
  148.                 }
  149.                 else{
  150.                     ret[j] = 'C';
  151.                 }
  152.                 F ^= 1;
  153.             }
  154.         }
  155.         else if(C > B){
  156.             B -= mnn;
  157.             C -= mxx;
  158.             if(B < 0 or C < 0) return 0 * printf("-1\n");
  159.             int F = 1;
  160.             for(int j = odd[i].first; j <= odd[i].second; j ++){
  161.                 if(F == 0){
  162.                     ret[j] = 'B';
  163.                 }
  164.                 else{
  165.                     ret[j] = 'C';
  166.                 }
  167.                 F ^= 1;
  168.             }
  169.         }
  170.         else{
  171.             return 0 * printf("-1\n");
  172.         }
  173.     }
  174.      
  175.      
  176.      
  177.     ret.erase(ret.begin());
  178.     cout << ret << endl;
  179.     return 0;
  180. }
  181. // BABABCACACBC
  182. // BACABCACABCB
Add Comment
Please, Sign In to add comment