Advertisement
BaoJIaoPisu

Untitled

Oct 17th, 2022
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using ll = long long;
  6. using ld = long double;
  7. using ull = unsigned long long;
  8.  
  9. using pii = pair<int, int>;
  10. using pll = pair<ll, ll>;
  11. using pld = pair<ld, ld>;
  12.  
  13. #define fi first
  14. #define se second
  15. #define pb push_back
  16. #define pf push_front
  17. #define mp make_pair
  18. #define ins insert
  19. #define btpc __builtin_popcount
  20. #define btclz __builtin_clz
  21.  
  22. #define sz(x) (int)(x.size());
  23. #define all(x) x.begin(), x.end()
  24. #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  25.  
  26. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  27.  
  28. int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
  29. int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  30. int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  31.  
  32. template<class X, class Y>
  33.     bool minimize(X &x, const Y &y) {
  34.         if (x > y)
  35.         {
  36.             x = y;
  37.             return true;
  38.         }
  39.         return false;
  40.     }
  41. template<class X, class Y>
  42.     bool maximize(X &x, const Y &y) {
  43.         if (x < y)
  44.         {
  45.             x = y;
  46.             return true;
  47.         }
  48.         return false;
  49.     }
  50.  
  51. const int MOD = 1e9 + 7; //998244353
  52.  
  53. template<class X, class Y>
  54.     void add(X &x, const Y &y) {
  55.         x = (x + y);
  56.         if(x >= MOD) x -= MOD;
  57.     }
  58.  
  59. template<class X, class Y>
  60.     void sub(X &x, const Y &y) {
  61.         x = (x - y);
  62.         if(x < 0) x += MOD;
  63.     }
  64.  
  65. /* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/
  66.  
  67. const ll INF = 1e9;
  68. const int N = 1e5 + 10;
  69.  
  70. void solve() {
  71.     int n; cin >> n;
  72.     string s; cin >> s;
  73.     string ans = "";
  74.  
  75.     string curr = "";
  76.     for(int i = 0; i < n; i++) {
  77.         char c;
  78.         if(curr.size() & 1) c = 'b';
  79.         else c = 'a';
  80.         if(s[i] == c) {
  81.             curr += c;
  82.         } else {
  83.             if(curr.size() && curr.back() == 'b') {
  84.                 string tmp = "";
  85.                 for(int i = 0; i + 1 < curr.size(); i++) tmp += curr[i];
  86.                 curr = tmp;
  87.             }
  88.             if(ans.size() < curr.size()) ans = curr;
  89.             curr = "";
  90.             if(s[i] == 'a') i--;
  91.         }
  92.     }
  93.  
  94.     if(curr.size() && curr.back() == 'b') {
  95.         string tmp = "";
  96.         for(int i = 0; i + 1 < curr.size(); i++) tmp += curr[i];
  97.         curr = tmp;
  98.     }
  99.     if(ans.size() < curr.size()) ans = curr;
  100.  
  101.     cout << ans;
  102. }
  103.  
  104. int main()
  105. {
  106.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  107.     #ifndef ONLINE_JUDGE
  108.     freopen("input.txt", "r", stdin);
  109.     freopen("output.txt", "w", stdout);
  110.     #else
  111.     //online
  112.     #endif
  113.  
  114.     int tc = 1, ddd = 0;
  115.     // cin >> tc;
  116.     while(tc--) {
  117.         //ddd++;
  118.         //cout << "Case #" << ddd << ": ";
  119.         solve();
  120.     }
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement