This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
// Stores the current text and history of commands
vector<char> text;
stack<pair<int, vector<char>>> history;
void Init() {
// Initialize empty text and history
text.clear();
history.push({0, vector<char>()});
}
void TypeLetter(char L) {
// Append letter to text and update history
text.push_back(L);
history.push({history.top().first + 1, vector<char>()});
}
void UndoCommands(int U) {
// Undo U commands in reverse order
for (int i = 0; i < U; i++) {
int prevSize = history.top().first;
vector<char> undo = history.top().second;
// If TypeLetter was undone, remove the letter and previous commands
if (undo.empty()) {
text.resize(prevSize);
} else {
// Redo previously undone commands (UndoCommands)
for (char c : undo) {
text.push_back(c);
}
}
history.pop();
}
}
char GetLetter(int P) {
// Return letter at position P based on current state
return text[P];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |