// P3952 [NOIP2017 提高组] 时间复杂度
// 125 MB 1000 ms
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define mst(a, k) memset(a, k, sizeof a)
#define minv(a, b) a = min(a, b)
#define maxv(a, b) a = max(a, b)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define mts() int t; scanf("%d", &t); while (t--) cout << ans[solve()] << '\n'
#define inf 0x3f3f3f3f
#define infl ((ll)1e18)
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long;
int read(char* s) {
int x = 0, f = 0, c = 1;
for (; !isdigit(s[c]); ++c) f |= s[c] == 'n';
for (; isdigit(s[c]); ++c) x = x * 10 + s[c] - 48;
return x = f ? x : -x;
}
void read(string& s1, string& s2, string S) {
int pos;
for (pos = 4; pos <= (int)S.size() - 1 && S[pos] != ' '; ++pos) s1 += S[pos];
// fprintf(stderr, "%d\n", pos);
for (; pos <= (int)S.size() - 1 && S[pos] == ' '; ++pos);
for (; pos <= (int)S.size() - 1 && S[pos] != ' '; ++pos) s2 += S[pos];
}
string ans[3] = { "Yes", "No", "ERR" };
int n, O;
int w[200], c[200];
int solve() { // t: 10 L: 100
char s[20];
scanf("%d %s", &n, s + 1);
O = read(s);
// fprintf(stderr, "%d %s %d\n", n, s + 1, O);
getchar(); int sts = 0, f1 = 0, f2 = 0, f2_old = 0, f3 = 0;
// f1: repeated value
// f3: F i a b(a <=> b)
string S; char val[107]; int top = 0;
rep (i, 1, n) {
getline(cin, S);
// S[0] == 'F' ? ++sts : --sts;
f2_old = maxv(f2_old, f2);
if (sts == 0) f2 = 0, f3 = 0, top = 0;
if (S[0] == 'F') {
++sts;
w[sts] = w[sts-1];
c[sts] = 0;
rep (j, 1, top) if (S[2] == val[j]) f1 = 1;
if (!f1) val[++top] = S[2];
else {
rep (j, i + 1, n) getline(cin, S);
break;
}
string s1 = "", s2 = "";
read(s1, s2, S);
// cerr << '#' << i << ' ' << (s1 == "n") << ' ' << (s2 == "n") << '\n';
if (s1 != "n" && s2 != "n") {
int a1, a2;
stringstream ss;
ss << s1, ss >> a1, ss.clear(); ss << s2, ss >> a2;
// cerr << '#' << i << ' ' << s1 << ' ' << s2 << '\n';
// fprintf(stderr, "#%d a1 = %d a2 = %d\n\n", i, a1, a2);
if (a1 > a2) w[sts]= 1;
} else if (!w[sts]) {
if (s1 == "n" && s2 != "n") w[sts] = 1;
else if (s1 != "n" && s2 == "n") ++f2,c[sts]=1;
}
// fprintf(stderr, "#%d f3 = %d\n", i, f3);
} else {
f2 -= c[sts];
--sts, --top;
if(sts < 0) {
f1=1;
rep(j, i + 1, n) getline(cin, S);
break;
}
}
}
maxv(f2, f2_old);
if (f2 == 0) f2 = -1;
// fprintf(stderr, "%d ", sts);
// fprintf(stderr, "f2 = %d, O = %d\n", f2, O);
if (sts || f1) return 2;
if (f2 == O) return 0; else return 1;
}
int main() {
mts();
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 44.94 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #2 | 50.65 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #3 | 67.92 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #4 | 82.29 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #5 | 69.22 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #6 | 59.53 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #7 | 100.91 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #8 | 103.62 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #9 | 104.16 us | 36 KB | Accepted | Score: 10 | 显示更多 |
Testcase #10 | 164.63 us | 36 KB | Accepted | Score: 10 | 显示更多 |