/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 135ms 3.254 MiB
#4 Accepted 69ms 7.176 MiB
#5 Accepted 2ms 320.0 KiB
#6 Accepted 148ms 2.27 MiB
#7 Accepted 142ms 2.141 MiB
#8 Accepted 27ms 1.062 MiB
#9 Accepted 94ms 8.199 MiB
#10 Accepted 123ms 7.824 MiB
#11 Accepted 41ms 3.746 MiB
#12 Accepted 83ms 7.797 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-11-11 02:59:56
Judged By
Score
100
Total Time
148ms
Peak Memory
8.199 MiB