悬关求调 37pts & 9pts
查看原帖
悬关求调 37pts & 9pts
637788
kimi0705楼主2023/10/12 22:49

代码1

#include <bits/stdc++.h>
#define int long long
using namespace std;
int t, n, c, ans, now, cnt;
char ch;
set<char> S;
stack<char> Stack;
stack<string> Stack1;
vector<string> Input;
bool check() { // 判断
    S.clear();
    while (Stack.size()) Stack.pop();
    for (string i : Input) {
        if (i[0] == 'F') {
            ch = i[2];
            if (S.count(ch) == 1) return false;
            S.insert(ch);
            Stack.push(ch);

        } else {
            if (Stack.size() == 0) return false;
            S.erase(Stack.top());
            Stack.pop();
        }
    }
    return !Stack.size();
}
bool run(string s) {
    int i = 4;
    if (s[4] == 'n') return false;
    while (s[i] != ' ') i++;
    i++;
    if (s[i] != 'n') return false;
    return true;
}
signed main() {
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld", &n);
        getchar(), getchar(), getchar();
        ch = getchar();
        if (ch == '1')
            c = 0, getchar(), getchar();
        else
            getchar(), scanf("%lld", &c), getchar(), getchar();
        Input.resize(n);
        for (string& i : Input) getline(cin, i);
        if (!check()) {
            puts("ERR");
        } else {
            ans = 0, now = 0, cnt = 0;
            while (Stack1.size()) Stack1.pop();
            for (string i : Input) {
                if (i[0] == 'F') {
                    if (run(i)) {
                        if (cnt == 0)
                            now++, ans = max(ans, now);
                    } else {
                        cnt++;
                    }
                    Stack1.push(i);
                } else {
                    if (run(Stack1.top())) {
                        if (cnt == 0) now--;
                    } else {
                        cnt--;
                    }
                    Stack1.pop();
                }
            }
            printf(ans == c ? "Yes\n" : "No\n");
        }
    }
}

WA 2 4 5 6 7 8 10

#2
2
8 O(n^2)
F a 57 n
F b 69 92
F c 85 87
F d 38 n
E
E
E
E
2 O(n^1)
F a 27 n
E
Yes
Yes


Code 2

#include <bits/stdc++.h>
#define int long long
using namespace std;
int t, n, c, ans, now, cnt;
char ch;
set<char> S;
stack<char> Stack;
stack<string> Stack1;
vector<string> Input;
bool check() { // 判断
    S.clear();
    while (Stack.size()) Stack.pop();
    for (string i : Input) {
        if (i[0] == 'F') {
            ch = i[2];
            if (S.count(ch) == 1) return false;
            S.insert(ch);
            Stack.push(ch);

        } else {
            if (Stack.size() == 0) return false;
            S.erase(Stack.top());
            Stack.pop();
        }
    }
    return !Stack.size();
}
bool In(string s) {
    if (s[4] == 'n' && s[6] == 'n') return true;
    if (s[4] == 'n') return false;
    int i = 4, num1 = 0, num2 = 0;
    while (s[i] != ' ') num1 = num1 * 10 + s[i] - '0', i++;
    i++;
    if (s[i] == 'n') return true;
    while (i < s.size()) num2 = num2 * 10 + s[i] - '0', i++;
    return num1 <= num2;
}
bool run(string s) {
    int i = 4;
    if (s[4] == 'n') return false;
    while (s[i] != ' ') i++;
    i++;
    if (s[i] != 'n') return false;
    return true;
}
signed main() {
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld", &n);
        getchar(), getchar(), getchar();
        ch = getchar();
        if (ch == '1')
            c = 0, getchar(), getchar();
        else
            getchar(), scanf("%lld", &c), getchar(), getchar();
        Input.resize(n);
        for (string& i : Input) getline(cin, i);
        if (!check()) {
            puts("ERR");
        } else {
            ans = 0, now = 0, cnt = 0;
            while (Stack1.size()) Stack1.pop();
            for (string i : Input) {
                if (i[0] == 'F') {
                    if(In(i)) {
                        if(run(i) && cnt == 0) 
                            now++, ans = max(ans, now);
                    } else {
                        cnt++;
                    }
                    Stack1.push(i);
                } else {
                    if (In(i)) {
                        if (run(i))
                            now--;
                    } else {
                        cnt--;
                    }
                    Stack1.pop();
                }
            }
            printf(ans == c ? "Yes\n" : "No\n");
        }
    }
}

#4 AC #9 #10 WA 其余 RE

2023/10/12 22:49
加载中...