/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 130ms 3.336 MiB
#4 Accepted 76ms 7.789 MiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 145ms 2.359 MiB
#7 Accepted 137ms 2.062 MiB
#8 Accepted 27ms 996.0 KiB
#9 Accepted 102ms 8.066 MiB
#10 Accepted 128ms 7.738 MiB
#11 Accepted 41ms 3.547 MiB
#12 Accepted 85ms 7.238 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define f(i,x,y) for(int i=x;i<y;i++)
#define f2(i,x,y) for(int i=x;i>=y;i--)
#define pii pair<int,int>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int MOD =1000000007;
const int INF = 1e18;
const int N = 2e5;
 
void solve(int tc){
    deque<char>d;
    string s; cin >> s;
    for(auto it : s)d.push_back(it);
    int rev = 0;
    int q; cin >> q;
    while(q--){
        int t; cin >> t;
        if(t==1)rev = 1 - rev;
        else{
            int dd;char c; cin >> dd >> c;
            if(rev==0){
                if(dd==1)d.push_front(c);
                else d.push_back(c);
            }
            else {
                if(dd==2)d.push_front(c);
                else d.push_back(c);
            }
        }
    }
    if(rev==0){
        while(!d.empty()){
            cout << d.front();
            d.pop_front();
        }
    }
    else{
        while(!d.empty()){
            cout << d.back();
            d.pop_back();
        }
    }
    cout << endl;
}
int32_t main(){

    Fast

    int t=1;

    cin >> t;

    for(int tc=1;tc<=t;tc++){

        solve(tc);
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Language
C++20 (G++ 13.2.0)
Submit At
2024-10-03 14:46:09
Judged At
2024-11-11 02:51:20
Judged By
Score
100
Total Time
145ms
Peak Memory
8.066 MiB