QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236643#7518. GCD of Pattern MatchingKevin5307WA 0ms3804kbC++141.5kb2023-11-04 09:25:272023-11-04 09:25:27

Judging History

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

  • [2023-11-04 09:25:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2023-11-04 09:25:27]
  • 提交

answer

//Author: Kevin5307
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int p[30];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int d;
		cin>>d;
		string s;
		cin>>s;
		memset(p,-1,sizeof(p));
		for(int i=sz(s)-1;i>=0;i--)
			p[s[i]-'a']=i;
		ull g=0;
		for(int i=0;i<sz(s);i++) if(p[s[i]-'a']==i)
			for(int j=i+1;j<sz(s);j++) if(p[s[j]-'a']==j)
			{
				ull val=0;
				for(int x=0;x<sz(s);x++)
				{
					val*=d;
					if(s[i]==s[x])
						val++;
					if(s[j]==s[x])
						val--;
				}
				g=__gcd(g,val);
			}
		int cnt=0;
		for(int i=0;i<26;i++)
			if(p[i]>=0)
				cnt++;
		if(cnt!=d)
		{
			for(int i=0;i<sz(s);i++)
				if(p[s[i]-'a']==i)
				{
					ull val=0;
					for(int j=0;j<sz(s);j++)
					{
						val*=d;
						if(s[j]==s[i])
							val++;
					}
					g=__gcd(g,val);
				}
		}
		cout<<g<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

input:

5
10 ccpcccpc
10 cpcpcp
10 cpc
4 cpccpc
4 dhcp

output:

10001
10101
1
65
3

result:

ok 5 number(s): "10001 10101 1 65 3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3804kb

input:

30
2 ab
3 abc
4 abcd
5 abcde
6 abcdef
7 abcdefg
8 abcdefgh
9 abcdefghi
10 abcdefghij
11 abcdefghijk
12 abcdefghijkl
13 abcdefghijklm
14 abcdefghijklmn
15 abcdefghijklmno
16 abcdefghijklmnop
16 a
16 ab
16 abc
16 abcd
16 abcde
16 abcdef
16 abcdefg
16 abcdefgh
16 abcdefghi
16 abcdefghij
16 abcdefghijk
...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'