/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Accepted 1ms 432.0 KiB
#3 Accepted 121ms 3.258 MiB
#4 Accepted 64ms 7.336 MiB
#5 Accepted 1ms 328.0 KiB
#6 Accepted 138ms 2.223 MiB
#7 Accepted 126ms 2.156 MiB
#8 Accepted 26ms 876.0 KiB
#9 Accepted 88ms 7.977 MiB
#10 Accepted 117ms 7.93 MiB
#11 Accepted 37ms 3.543 MiB
#12 Accepted 72ms 7.777 MiB

Code

#include <bits/stdc++.h>
using namespace std;

void solve() {
    string s;
    cin >> s;

    int q;
    cin >> q;

    bool isReversed = false;
    deque<char> dq(s.begin(), s.end());  // Using deque to perform efficient front and back operations

    while (q--) {
        int type;
        cin >> type;

        if (type == 1) {
            // Toggle the reversed state
            isReversed = !isReversed;
        } else {
            int d;
            char c;
            cin >> d >> c;

            if (!isReversed) {
                // Normal order
                if (d == 1) {
                    dq.push_front(c);  // Append to the front
                } else {
                    dq.push_back(c);   // Append to the back
                }
            } else {
                // Reversed order
                if (d == 1) {
                    dq.push_back(c);   // In reversed state, appending to front is like appending to back
                } else {
                    dq.push_front(c);  // In reversed state, appending to back is like appending to front
                }
            }
        }
    }

    // If the string is reversed at the end, reverse the deque before printing
    if (isReversed) {
        reverse(dq.begin(), dq.end());
    }

    for (char c : dq) {
        cout << c;
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Contest
Brain Booster #5
Language
C++17 (G++ 13.2.0)
Submit At
2024-09-05 16:39:06
Judged At
2024-10-03 13:06:39
Judged By
Score
100
Total Time
138ms
Peak Memory
7.977 MiB