QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738418#5311. Master of BothEMTzWA 88ms57932kbC++201.7kb2024-11-12 19:01:182024-11-12 19:01:19

Judging History

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

  • [2024-11-12 19:01:19]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:57932kb
  • [2024-11-12 19:01:18]
  • 提交

answer

#include<bits/stdc++.h>
//#define int long long
#define ull unsigned long long
using namespace std;
typedef pair<int,int>PII;
typedef pair<int,PII>PPI;
typedef array<int,3>ar;
typedef __int128 i28; 
const int N=1e6+100;
const int N1=1e9+9;
const int M=998244353;
const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(time(0));
const int M1=19260817;
const int base=233;
const int base1=131;
const int INF = 0x3f3f3f3f;
int tr[N][27],cnt[N];
int ans[27][27];
vector<int>p[27][27];
string s[N];
int idx=0;
int all=0;
int an[N];
void insert(string s)
{
	int n=s.length();
	int p=0;
	for(int i=0;i<n;i++)
	{
		if(tr[p][s[i]-'a']==0) tr[p][s[i]-'a']=++idx;
		p=tr[p][s[i]-'a'];
		cnt[p]++;
	}
}
void get(string s)
{
	int n=s.length();
	int p=0;
	for(int i=0;i<n;i++)
	{
		int d=s[i]-'a';
		for(int j=0;j<26;j++)
		{
			if(j==d) continue;
			int ne=tr[p][j];
			ans[d][j]+=cnt[ne];
		}
		p=tr[p][d];
		if(p==0) return;
	}
	for(int j=0;j<26;j++) all+=cnt[tr[p][j]];
	cout<<all<<"\n";
}
void solve()
{
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	for(int i=1;i<=q;i++)
	{
		string s1;
		cin>>s1;
		for(int j=0;j<=25;j++)
		{
			for(int k=j+1;k<=25;k++)
			{
				p[s1[j]-'a'][s1[k]-'a'].push_back(i);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		get(s[i]);
		insert(s[i]);
	}
//	cout<<all<<"\n";
	for(int j=0;j<=25;j++)
	{
		for(int k=0;k<=25;k++)
		{
			if(j==k) continue;
			for(auto v:p[j][k])
			{
				an[v]+=ans[j][k]+all;
			}
		}
	}
	for(int i=1;i<=q;i++) 
	{
		cout<<an[i]<<"\n";
	}
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cout.tie(0);cin.tie(0);
	int _=1;
//	cin>>_;
	while(_--)
	{
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 36704kb

input:

5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg

output:

4
3
4

result:

ok 3 number(s): "4 3 4"

Test #2:

score: 0
Accepted
time: 8ms
memory: 57932kb

input:

100 100
spkfvrbkfsspmnlgrdojwdqutknvzejorqxsmfgbfrhpxkrrtravhmxenjrzypkxounrbantpkaezlcnudjmwxpgqakfoxcmdjcygujdtpluovbisxmklkzzuuyziapzyrszcggjkzrwmtyolnbobubbezdwmumyzyhaogiiolictzjpxbyaamecytpnyzxlumxjkzyfavxlzdwtgrxtqcnddzfocznitlaxlpcceuelqlbmyzetlpaivxnuvuctsbjbaulmbmkangqahpdojqimvmcugjeczkgx...

output:

2368
2693
2179
2466
2435
2370
2604
2468
2335
2268
2686
2781
2538
2208
2386
2539
2728
2383
2248
2372
2446
2266
2290
2688
2602
2515
2634
2558
2598
2632
2763
2255
2557
2579
2367
2516
2676
2273
2429
2556
2576
2635
2422
2829
2362
2552
2377
2261
2603
2516
2298
2282
2520
2333
2505
2287
2261
2476
2791
2328
...

result:

ok 100 numbers

Test #3:

score: -100
Wrong Answer
time: 88ms
memory: 51172kb

input:

500000 5
ru
x
tb
s
e
w
e
m
l
b
g
zr
jp
h
js
xk
fjwtk
wtkem
o
ev
a
a
x
sy
dh
y
kkdcxfr
hgq
j
k
xr
s
cvwbrlk
u
u
x
wtvgef
dzxsk
qv
gxl
g
m
rpl
ldp
q
lc
dk
g
k
im
o
yhn
z
a
knc
tyv
mz
ak
qdhq
c
niw
o
j
heu
w
g
e
kt
n
inqt
i
al
q
ebphky
sv
m
mry
oj
cl
j
r
sf
vpd
u
rio
sfkg
m
el
s
zs
g
o
e
njp
r
xczcm
gh...

output:

0
0
1
3
4
5
5
7
8
8
9
10
11
11
12
12
13
13
15
17
18
19
20
22
24
25
27
29
29
31
35
36
37
40
43
45
46
49
51
53
53
56
59
60
62
65
69
70
72
74
76
79
81
85
89
90
93
98
99
102
105
108
111
115
118
121
125
127
133
136
138
139
142
145
148
153
159
165
171
173
175
177
181
186
189
191
193
196
199
204
211
211
21...

result:

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