求调 洛谷82pts
#include #include #include #include <unordered_map>
using namespace std; const int N = 110; int top;
int T, n; string s; string stk[N]; unordered_map <string, int> mp; int get (string a, string b) { if (b == "n") return 1; return 0; } int main() { cin >> T; while (T -- ) {
mp.clear ();
top = 0;
cin >> n >> s;
getchar ();
int t = 0;
int cnt = 0;
bool f = 0;
int flag = -1;
int last = 0;
for (int i = 1; i <= n; i ++ )
{
if (top == 0) cnt = 0;
t = max (t, cnt);
char op;
cin >> op;
if (op == 'F')
{
string a, b, c;
cin >> a >> b >> c;
if (mp[a]) f = 1;
mp[a] = 1;
stk[ ++ top] = a;
if (b == "n" || b != "n" && c != "n" && stoi (b) > stoi (c) && flag == -1) flag = top, last = i;
if (top < flag && flag != -1 || flag == -1) cnt += get (b, c);
if (top == flag && i != last) flag = -1, last = 0;
}
else
{
if (!top) f = 1;
string t = stk[top -- ];
mp[t] = 0;
cnt -- ;
}
t = max (t, cnt);
}
t = max (t, cnt);
if (top || f == 1) cout << "ERR\n";
else
{
string ans = "";
if (t == 0)
{
ans = "O(1)";
}
else
{
ans = "O(n^" + to_string(t) + ")";
}
if (ans == s) cout << "Yes\n";
else cout << "No\n";
}
}
}
```