本地过了为什么交上去没过
查看原帖
本地过了为什么交上去没过
550570
JanF楼主2025/8/29 08:19
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
map<string, int> mp;
int m, n, p;
string word[N];
string ss[N];

struct node
{
    int who, to, is;
} now[N];

int count(int p)
{
    int x = p, cnt = 0;
    while (x)
    {
        cnt++;
        x &= (x - 1);
    }
    return cnt;
}

int to(string s)
{
    if (s == "Monday")
        return 1;
    if (s == "Tuesday")
        return 2;
    if (s == "Wednesday")
        return 3;
    if (s == "Thurday")
        return 4;
    if (s == "Friday")
        return 5;
    if (s == "Saturday")
        return 6;
    if (s == "Sunday")
        return 7;
    else
        return -1;
}

node getword(string s)
{
    node res = {-1, -1, -1};
    int las = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == ':')
        {
            string W = s.substr(0, i);
            res.who = mp[W];
        }
        else if (s[i] == ' ')
        {
            if (las == 0)
                las = i;
            else
            {
                string now = s.substr(las + 1, i - las - 1);
                // cout << las << ' ' << i << ' ' << now << ' ' << (now == "am") << endl;
                if (now == "Today")
                    res.to = m + 1;
                else if (mp[now] != 0)
                    res.to = mp[now];
                else if (now == "I")
                    res.to = res.who;
                else if (now == "am")
                    res.is = 1;
                else if (now == "is")
                {
                    if (res.to != m + 1)
                        res.is = 1;
                }
                else if (now == "not")
                    res.is = 0;
                else
                    res.is = to(now);
                las = i;
            }
        }
        else if (s[i] == '.')
        {
            if (res.to == m + 1)
            {
                string now = s.substr(las + 1, i - las - 1);
                // cout << now << endl;
                res.is = to(now);
            }
            else
            {
                string now = s.substr(las + 1, i - las - 1);
                if (now != "guilty")
                    res.is = -1;
            }
        }
    }
    return res;
}
int main()
{
    cin >> m >> n >> p;
    string s;
    getline(cin, s);
    for (int i = 1; i <= m; i++)
    {
        getline(cin, s);
        ss[i] = s;
        mp[s] = i;
        // cout << mp["GUILTY"] << endl;
    }
    for (int i = 1; i <= p; i++)
    {
        getline(cin, word[i]);
        // cout << word[i] << endl;
        now[i] = getword(word[i]);
        // cout << now[i].who << ' ' << now[i].to << ' ' << now[i].is << endl;
    }
    int ans = 0, qfz = 0, q = 0;
    for (int i = 0; i < (1 << m); i++)
    {
        int num = count(i);
        if (num != n)
            continue;
        int day = -1, stda = 0, flag = 0, fz = -1, nfz = 0, k = ans;
        // cout << i << endl;
        for (int j = 1; j <= p; j++)
        {
            int nowp = now[j].who, tt = now[j].to, st = now[j].is;
            // cout << nowp << ' ' << tt << ' ' << st << endl;
            if (tt == -1 || st == -1)
                continue;
            if (tt == m + 1)
            {
                if ((i >> (nowp - 1)) & 1 == 1)
                {
                    if (st == day)
                    {
                        flag = 1;
                        break;
                    }
                    else
                        stda |= (1 << (st - 1));
                }
                else
                {
                    if ((stda >> (st - 1)) & 1 == 1)
                    {
                        flag = 1;
                        break;
                    }
                    else if (day != -1 && day != st)
                    {
                        flag = 1;
                        break;
                    }
                    else if (day == -1)
                        day = st;
                }
            }
            else
            {
                if ((((i >> (nowp - 1)) & 1 == 1) && st == 1) || (((i >> (nowp - 1)) & 1 == 0) && st == 0))
                {
                    if (fz == tt)
                    {
                        flag = 1;
                        break;
                    }
                    else
                        nfz |= (1 << (tt - 1));
                }
                else
                {
                    // cout << "IN" << endl;
                    if ((nfz >> (tt - 1)) & 1 == 1)
                    {
                        flag = 1;
                        break;
                    }
                    else if (fz != -1 && fz != tt)
                    {
                        // cout << "IN " << j << endl;
                        ans = 2;
                        // break;
                    }
                    else if (fz == -1)
                    {
                        fz = tt;
                        if ((qfz >> (tt - 1)) & 1 == 1)
                            ans = 2;
                    }
                }
            }
            // cout << day << ' ' << fz << endl;
        }
        if (flag && ans == 2 && ans != k)
            ans = 0;
        // cout << "F " << flag << ' ' << fz << ' ' << ans << endl;
        if (!flag && fz != -1 && ans != 2)
            ans = 1, q = fz, qfz |= (1 << (q - 1));
    }
    // cout << ans << endl;
    if (ans == 1)
        cout << ss[q] << endl;
    if (ans == 2)
        cout << "Cannot Determine\n";
    if (ans == 0)
        cout << "Impossible\n";
    return 0;
}

rt 下载了第3个点 输入

2 2 4
HELLO
GUILTY
HELLO: What is your name?
GUILTY: I am GUILTY.
GUILTY: Are you guilty?
HELLO: I am not guilty.

输出

HELLO

我完全可以输出一样的答案,交上去就WA了。玄关。

2025/8/29 08:19
加载中...