QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#114829#5319. Universal Question Answering SystemPetroTarnavskyi#WA 750ms3540kbC++172.7kb2023-06-23 17:29:422023-06-23 17:29:43

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-23 17:29:43]
  • 评测
  • 测评结果:WA
  • 用时:750ms
  • 内存:3540kb
  • [2023-06-23 17:29:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 474;
VI g[N];
VI g2[N];
bool used[N];
int type[N];
map<string, int> m;

void add(string& s, int t)
{
	s += char(t + '0');
	if (!m.count(s))
		m[s] = SZ(m);
	type[m[s]] = t;
}

void dfs(int v)
{
	used[v] = 1;
	for (auto to : g[v])
		if (!used[to])
			dfs(to);
}

void dfs2(int v, VI& res)
{
	used[v] = 1;
	if (type[v] == 0)
		res.PB(v);
	for (auto to : g2[v])
		if (!used[to])
			dfs2(to, res);
	
}

void solve()
{
	
	while (true)
	{
		string s;
		getline(cin, s);
		if (s.back() == '!')
			break;
		char c = s.back();
		s.pop_back();
		stringstream ss(s);
		vector<string> v;
		while (!ss.eof())
		{
			string t;
			ss >> t;
			v.PB(t);
		}
		if (c == '.')
		{
			if (v[1] == "can")
			{
				add(v[0], 0);
				add(v[2], 1);
				g[m[v[0]]].PB(m[v[2]]);
				g2[m[v[2]]].PB(m[v[0]]);
			}
			else if (v[1] == "are")
			{
				add(v[0], 0);
				add(v[2], 0);
				g[m[v[0]]].PB(m[v[2]]);
				g2[m[v[2]]].PB(m[v[0]]);
			}
			else if (v[4] == "can")
			{
				add(v[3], 1);
				add(v[5], 1);
				g[m[v[3]]].PB(m[v[5]]);
				g2[m[v[5]]].PB(m[v[3]]);
			}
			else if (v[4] == "are")
			{
				add(v[3], 1);
				add(v[5], 0);
				g[m[v[3]]].PB(m[v[5]]);
				g2[m[v[5]]].PB(m[v[3]]);
			}
		}
		else if(c == '?')
		{
			if (SZ(v) == 3)
			{
				string s1 = v[1];
				string s2 = v[2];
				if (v[0] == "can")
					add(s2, 1);
				else
					add(s2, 0);
				add(s1, 0);
				dfs(m[s1]);
				if (used[m[s2]]) cout << 'Y';
				else cout << 'M';
				FOR(i, 0, SZ(m)) used[i] = 0;
			}
			else
			{
				string s1 = v[4];
				string s2 = v[5];
				add(s1, 1);
				if (v[0] == "can")
					add(s2, 1);
				else
					add(s2, 0);
				VI v1, v2;
				dfs2(m[s1], v1);
				FOR (i, 0, SZ(m)) used[i] = 0;
				dfs2(m[s2], v2);
				FOR (i, 0, SZ(m)) used[i] = 0;
				
				int j = 0;
				FOR (i, 0, SZ(v1))
					if (j < SZ(v2) && v1[i] == v2[j])
						j++;
				cout << (j == SZ(v2) ? 'Y' : 'M');
			}
		}
		else
			assert(0);
	}
	int x = SZ(m);
	FOR (i, 0, x)
	{
		g[i].clear();
		g2[i].clear();
		type[i] = -1;
	}
	m.clear();
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string str;
	getline(cin, str);
	int t = stoi(str);
	while (t--)
	{
		solve();
	}
	
		
	return 0;
}


详细

Test #1:

score: 0
Wrong Answer
time: 750ms
memory: 3540kb

input:

500
are can X?
everything which can can are Bfheze.
everything can vwya.
everything which can B can B.
everything which can are can Lnx.
can are Tozngr.
everything which can Lnx can B.
can X Qrmoikaxqs?
everything which can Qrmoikaxqs can Qrmoikaxqs.
Bfheze can Lnx.
are which uhsrxrm?
are uhsrxrm ed...

output:

MMMMYYMYMYMMMMMMMMMYMYYMMYMYMMMMYMMMYYMYMYMMMMMYYMMYMYYYYYYYYYMMYYMYMMMMMYYYMMMYMYYYYMMYYYYMMMYMMMMMYYYYYMYYMMMMMYMYYMMMMMYMYMYMYMYYMMYYYYYMMMMMMYMMYMMYMMYMYYMMYYYMMYMYMMYMYYYYMMMYMYYMYMMYYYMYYYYYYYMMYMYYYMMYYYYMYYMYMYYYMYYYYMYYMYMMMYYYMYYYYYMMYMMMMYMYYMYMYMYMYMMYYYYYYMYMYMYMMMMMYMM
MMMMMMMMMMYMMMMM...

result:

wrong answer 1st lines differ - expected: 'Case #1:', found: 'MMMMYYMYMYMMMMMMMMMYMYYMMYMYMM...YMYMYMYMYMMYYYYYYMYMYMYMMMMMYMM'