社区讨论

63pts 求条

P3952[NOIP 2017 提高组] 时间复杂度参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mj5i43ez
此快照首次捕获于
2025/12/14 17:07
2 个月前
此快照最后确认于
2025/12/17 19:20
2 个月前
查看原帖
https://www.luogu.com.cn/record/253230211
按照评测记录的反馈,推测:部分 ERR 输出了 No
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct forstt
{
    char var;
    ll cur;
};
ll n, exc, ans;
string str;
map<char, bool> isn;
stack<forstt> forsts;
ll strtoll(string str)
{
    if (islower(str[0]))
    {
        return 1;
    }
    ll s = 0, c = 1;
    if (str[0] == '-')
    {
        c = -1;
    }
    for (char ch : str)
    {
        if (isdigit(ch))
        {
            s = s * 10 + ch - '0';
        }
    }
    return c * s;
}
void solve()
{
    isn.clear();
    isn['n'] = true;
    while (forsts.size())
    {
        forsts.pop();
    }
    forsts.push({'n', 0});
    ans = 0;
    cin >> n >> str;
    if (str != "O(1)")
    {
        exc = strtoll(str.substr(4, str.size() - 5));
    }
    else
    {
        exc = 0;
    }
    while (n--)
    {
        char op, i;
        string x, y;
        cin >> op;
        if (op == 'F')
        {
            cin >> i >> x >> y;
            if (isn.count(i))
            {
                cout << "ERR\n";
                return;
            }
            isn[i] = islower(x[0]) && isn[x[0]] || islower(y[0]) && isn[y[0]];
            if (islower(x[0]) && isn[x[0]])
            {
                if (islower(y[0]) && isn[y[0]])
                {
                    forsts.push({i, forsts.top().cur});
                }
                else
                {
                    forsts.push({i, -1});
                }
            }
            else
            {
                if (islower(y[0]) && isn[y[0]])
                {
                    forsts.push({i, forsts.top().cur != -1 ? forsts.top().cur + 1 : -1});
                }
                else if (strtoll(x) <= strtoll(y))
                {
                    forsts.push({i, forsts.top().cur});
                }
                else
                {
                    forsts.push({i, -1});
                }
            }
            ans = max(ans, forsts.top().cur);
        }
        else if (op == 'E')
        {
            if (forsts.size() <= 1)
            {
                cout << "ERR\n";
                return;
            }
            isn.erase(forsts.top().var);
            forsts.pop();
        }
        else
        {
            getline(cin, str);
        }
    }
    if (forsts.size() == 1)
    {
        if (exc == ans)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }
    else
    {
        cout << "ERR\n";
    }
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...