Write a large simulation questions.
Since the limit is written, the code is equivalent to the examination room, a group of chaos.
Topic link: P3952 time complexity
Credited first few lessons:
- Compare the size of the string of numbers honestly write function, lexicographical have made a mistake a few times
- Stack empty when not only pop () will RE, top () will access the top of the stack RE
- Digital read as a character into consideration more than one digit
Ideas:
1. I use the online approach.
2. The memory structure using a loop, including a variable name, start and end, whether the n-related, is able to enter (this trouble, whether pushed on the stack with n-related and whether to enter the line)
3. Use of a variable stores the current into the layers (containing only referred to n), when pressed into a + "and n-related", when a pop-up "and the related n" -, takes a maximum value
4. Use a bool whether the current cycle into the memory. Cancel "can not enter the" pop-up when a state can not enter the structure (if the "inaccessible" state, the structure will not be referred to as "inaccessible")
Source:
//MiserWeyte is now "mzWyt"
#include <bits/stdc++.h>
using namespace std;
int n, tgt, rel, curr = 0, maxx;
bool used[30];
string tar;
bool err, notin;
struct sts{
char tpe, nam;
string sta, end;
bool use, nin;
};
bool le(string a, string b){
if(a=="n" || b=="n" ) return false;
int numa = atoi(a.c_str());
int numb = atoi(b.c_str());
return numa > numb;
}
stack <sts> s;
void init(){
err = false;
memset(used, 0, sizeof(used));
curr = 0;
maxx = 0;
notin = false;
while(s.size()) s.pop();
}
int main(){
int t;
cin >> t;
while(t--){
init();
cin >> n >> tar;
tgt = 0;
if(tar[2] != '1'){
for(int i=0; i<tar.length(); i++){
if(tar[i] >= '0' && tar[i] <= '9'){
tgt *= 10;
tgt += tar[i] - '0';
}
}
}
for(int i=0; i<n; i++){
sts temp;
cin >> temp.tpe;
if(temp.tpe == 'F'){
cin >> temp.nam ;
cin>> temp.sta;
cin>> temp.end;
temp.use = false;
temp.nin = false;
if(used[temp.nam - 'a']){
err = true;
// break;
}
used[temp.nam - 'a'] = true;
if(notin){
s.push(temp);
}
else if(temp.sta == "n" && temp.end == "n") s.push(temp);
else if(temp.sta != "n" && temp.end == "n"){
temp.use = true;
curr ++;
maxx = max(maxx, curr);
s.push(temp);
}
else if((temp.sta == "n" && temp.end != "n") || le(temp.sta, temp.end)){
notin = true;
temp.nin = true;
s.push(temp);
}
else s.push(temp);
}
else{
if(s.empty()){
err = true;
continue;
}
if(s.size() && s.top().use && !s.top().nin) curr --;
// cout << s.top().use;
if(s.size() && s.top().nin) notin = false;
used[s.top().nam - 'a'] = false;
if(s.size()) s.pop();
}
// cout << "curr" << curr << endl;
// if(notin) cout << "NOTIN" << endl;
}
if(s.size()) err = true;
if(err) cout << "ERR\n";
else{
if(maxx == tgt) cout << "Yes\n";
else cout << "No\n";
// cout << curr << endl;
}
}
}