QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354081#7697. Impartial StringsPetroTarnavskyi#WA 1ms3612kbC++201.6kb2024-03-14 21:19:532024-03-14 21:19:54

Judging History

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

  • [2024-03-14 21:19:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3612kb
  • [2024-03-14 21:19:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

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

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

int sub(string sub, string s)
{
	int ans = 0;
	FOR(i, 0, SZ(s) - SZ(sub) + 1)
	{
		if(s.substr(i, SZ(sub)) == sub)
			ans++;
	}
	return ans;
}


bool check(string s, string t)
{
	RFOR(cnt, min(SZ(s), SZ(t)), 0)
	{
		string a = s.substr(SZ(s) - cnt, cnt);
		string b = t.substr(0, cnt);
		if(a != b)
			continue;
		
		string S = s;
		if(cnt != SZ(t))
			S += t.substr(cnt, SZ(t) - cnt);
		
		return sub(s, S) != sub(t, S);
	}
	assert(0);
}

int solve()
{
	string a, s, t;
	cin >> a >> s >> t;
	
	if(s == t)
		return 1;
	
	if(SZ(a) == 2)
	{
		if(SZ(s) != SZ(t))
			return 0;
		
		bool ok = 1;
		FOR(i, 0, SZ(s))
		{
			if(i % 2 == 0)
			{
				ok &= s[i] == s[0];
				ok &= t[i] == t[0];
			}
			else
			{
				ok &= s[i] != s[0];
				ok &= t[i] != t[0];
			}
		}
		return ok;
	}
	bool alp = 0;
	FOR(i, 0, SZ(a))
	{
		bool ok = 0;
		FOR(j, 0, SZ(s))
			ok |= s[j] == a[i];
		if(!ok)
			alp = 1;
		ok = 0;
		FOR(j, 0, SZ(t))
			ok |= t[j] == a[i];
		if(!ok)
			alp = 1;
		
	}
	
	if(check(s, t) || check(t, s) || alp)
		return 0;
	return 1;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	while(t--)
		cout << solve() << "\n";
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

3
ab ab ba
abc ab ba
cz cczz zzcc

output:

1
0
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3612kb

input:

7
d d d
d dd d
d d dd
z zzzzzzzzzzzz zzz
a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
0
0
0
1
0
0

result:

wrong answer 2nd lines differ - expected: '1', found: '0'