45分(玄学错误只求解惑不麻烦大佬们调了)

P3952 [NOIP2017 提高组] 时间复杂度

nmyxyc @ 2024-10-17 20:41:32

#include<bits/stdc++.h>
using namespace std;
const int N = 101;
int t, l, ans, sum, f, x, y, maxn, a[10], F, E; 
bool flag1, flag2[20], ex[30], flag3;
string s;
int main()
{
    scanf("%d", &t);
    while (t--)
    {
        flag1 = flag3 = 0;
        F = E = maxn = 0;
        memset(ex, 0, sizeof(ex));
        memset(flag2, 0, sizeof(flag2));
        scanf("%d ", &l);
        getline(cin, s);
        if (s[2] == 'n')
        {
            if (s[5] == ')') ans = s[4] - '0';
            else ans = (s[4] - '0') * 10 + s[5] - '0';
        }
        else ans = 0;
        for (int i = 1; i <= l; i++)
        {
            getline(cin, s);
            if (s[0] == 'F') F++;
            else E++;
            if (flag1 == 1) continue;
            if (s[0] == 'F')
            {
                if (flag3 == 1) continue;
                f++;
                if (ex[s[2] - 'a'] == 1)
                {
                    flag1 = 1;
                    continue;
                }
                else
                {
                    ex[s[2] - 'a'] = 1;
                    a[f] = s[2] - 'a';
                }
                if (s[4] == 'n')
                {
                    if (s[6] != 'n') flag2[f] = flag3 = 1;
                    continue;
                }
                if (s[5] == ' ')
                {
                    x = s[4] - '0';
                    if (s[7] == 'n' || s[6] == 'n') y = N;
                    else if (s[7] == ' ') y = s[6] - '0';
                    else y = (s[6] - '0') * 10 + s[7] - '0';
                }
                else
                {
                    x = (s[4] - '0') * 10 + s[5] - '0';
                    if (s[8] == 'n' || s[7] == 'n') y = N;
                    else if (s[8] == ' ') y = s[7] - '0';
                    else y = (s[7] - '0') * 10 + s[8] - '0';
                }
                if (y == N) sum++;
                else if (x >= y)
                {
                    if (x > y) flag2[f] = flag3 = 1;
                    continue;
                }
            }
            else
            { 
                flag2[f] = flag3 = ex[a[f]] = 0;
                f--;
                if (f == 0)
                {
                    memset(ex, 0, sizeof(ex));
                    maxn = max(maxn, sum);
                    sum = flag3 = 0;
                }
                else for (int j = 1; j <= f; j++) if (flag2[j] == 1)
                {
                    flag3 = 1;
                    break;
                }
            }
        }
        if (F != E) flag1 = 1;
        f = sum = 0;
        if (flag1 == 1)
        {
            printf("ERR\n");
            continue;
        }
        if (maxn == ans) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

为什么F的值在第十次循环时在第43行会莫名其妙的减一(大雾)。

1
44 O(n^9)
F a 84 85
F b 59 82
F c 81 n
F d 28 n
F e 63 95
F f 64 n
F g 24 70
F h 47 n
F i 3 78
F j 56 n
F k 36 n
F l 49 n
F m 49 n
F o 89 92
F p 34 n
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
F a 90 n
F b 1 n
F c 9 n
F d 53 86
F e 75 n
F f 8 n
F g 42 n
E
E
E
E
E
E
E

目前只发现这个数据有,其他的不清楚。求大佬解惑qwq


|