QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69018#5119. Perfect WordzhuibaoAC ✓20ms6828kbC++201.5kb2022-12-22 16:26:512022-12-22 16:26:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-22 16:26:53]
  • 评测
  • 测评结果:AC
  • 用时:20ms
  • 内存:6828kb
  • [2022-12-22 16:26:51]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) 
#include<unordered_map>
#include<unordered_set>
#include<bits/stdc++.h>
#include<array>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pi;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(ll i=a;i<=n;i++)
#define ref(i,n,a) for(ll i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------

const int N = 1e5 + 10;
set<string>se;
string s[N];

bool cmp(string a, string b)
{
	if (a.size() ^ b.size())return a.size() < b.size();
	return a < b;
}

void solve()
{
	int n;
	cin >> n;
	fer(i, 1, n)
	{
		cin >> s[i];
	}
	sort(s + 1, s + n + 1, cmp);
	int ans = 0;
	fer(i, 1, n)
	{
		bool flag = 1;
		int len = s[i].size();
		if (len == 1)
		{
			se.insert(s[i]);
			ans = len;
			continue;
		}
		string res = s[i].substr(1, len - 1);
		if (se.find(res) == se.end())flag = 0;
		res = s[i].substr(0, len - 1);
		if (se.find(res) == se.end())flag = 0;
		if (flag)
		{
			se.insert(s[i]);
			ans = len;
		}
	}
	cout << ans << endl;
}

AC

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 6552kb

input:

4
a
t
b
ab

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 4ms
memory: 6640kb

input:

310
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
aaaaaaaaa
aaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaaa
aaaaaaaaaaaaa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa...

output:

300

result:

ok 1 number(s): "300"

Test #3:

score: 0
Accepted
time: 3ms
memory: 6660kb

input:

4347
bbaaaab
aabab
bbaaaaababaaaba
aababaaaabbbabababaaaba
ababbabbbbbabbbabbab
bbbbbbb
bbbabbbabbabaab
aabbbbabbbbaa
aabaaabbbbbabaaababaa
aaabababba
aaababbaabab
abbababbabbab
bababaabbbbaaa
aaaaaabaaaababaa
ababaababba
babaababbbababaaab
bb
abbbaaaababa
b
ab
aaabbbbb
abaabaaaaababbbab
bbaaabaab
b...

output:

10

result:

ok 1 number(s): "10"

Test #4:

score: 0
Accepted
time: 9ms
memory: 6724kb

input:

5555
fdaaefdad
eacaeb
eeab
decaaddfdfffeb
ebcdeeceabfcded
aeeabcefdfdcb
abfdeeaac
daddadacebffcccb
abacccea
bcbec
ababfdaa
b
fbcccdbcdceafdefa
bdcd
a
ceaabbbae
e
eebeddcedecacafdc
ccdaebfd
ceeefb
baafbad
fadcaefbae
aad
a
dcdddedbdcdeabd
f
fdbccede
ebfb
efadfddddfed
fafefdfbdec
bcacbbafaaeddec
aebfec...

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 10ms
memory: 6620kb

input:

6249
a
a
aedbcbebea
bcebbaabeed
ebacbdbbaccdbbe
cceccaacb
ededaa
acdabaebaedab
bacdadacbec
ebbeaebabcebdd
bcec
adc
eeaaadba
eedabbaea
aadaadaecdcd
cdbdbddbababb
ea
ecccbebceddbae
ebaecdaebadad
ddccd
ebcebdcaecae
bccebebdcccbdbca
bccc
ebccdeeedbeea
aaedaeeaadbbbac
bbcee
caeccdbcbee
acbaabecccca
ea
cd...

output:

5

result:

ok 1 number(s): "5"

Test #6:

score: 0
Accepted
time: 3ms
memory: 6516kb

input:

3846
bcabccbcbcaabbaaaba
acabbbacccbbabbbc
ccabcbbacbc
bc
bbabaabcbcbbacbc
bccbcbbbbbcccbc
cabbcacaabcc
acaccccabbabbbbacaaabbaacb
bb
b
bcaccacbacabaaca
cbbacccbbcabcccbcac
bba
accbccacaaaccaccababba
aabcbabacabbaa
babcbbacaccababbbccbbb
acacaccbaccccbbbbcacbacba
aabaccaab
aacbcbbbbacabb
babaacccabc...

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 3ms
memory: 6740kb

input:

4166
dabdcacbdaeccdddbbdbaa
ebbe
aaebccdb
bbb
dbbcedbedcdcabebee
ceeeddaeeaabdc
bccdccecbcdbabbbea
bdbe
caebdbdddaaddeeacaacce
bcadededdebddcebdcee
ebddeeccaeacdab
ddedaccdbeeeacaeadcddcd
ca
ceddcedebcbbbaebdcdebcba
acaaaccaadb
da
edab
eadbaae
be
dabebdecdddbbcaaebcec
ababdbdcedcabbabdccea
eecdbdaad...

output:

5

result:

ok 1 number(s): "5"

Test #8:

score: 0
Accepted
time: 6ms
memory: 6596kb

input:

2777
cbccdbdbbeabbadfecfafebfaecdfefabccc
cd
b
eacefbcceada
ffebadacadfddeccadcabefcaeebaad
ebeccfdbfcadefcafefffbbddbedecab
dfbaaddcdafabbaafceadffefeddaaa
cdfdccedccddaceafccbfcaeebeda
cccbdebabcdaeebecbbbaaaebcbcfefbcda
cfefcabeaffcabdaabcbcfebfaeafeef
cdedd
debedaafaafbecfeedccaafeffbdbefedaa
fc...

output:

4

result:

ok 1 number(s): "4"

Test #9:

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

input:

3999
cbcbabccccbbcaaa
cbabaaaa
bbabbcbbbcbabcaaabc
aac
acaacbabcbabbbacabaccbaa
acbcbabcb
abbcbbbbcbaaacc
aabcaccbbbacbababcbaab
cbca
cca
bcabbccabbacaaacbaaaaaa
cabaaaabaabaaababbcc
ccacaaabacabacababcabbcab
babbbac
bbbbcaccbcaab
aca
bcbccccbaaccba
abcacaccccbbcbaccbacac
cacbaabaaabbca
bbcbbacb
cbb...

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 5ms
memory: 6636kb

input:

2083
edd
cdaacaeecadeadadd
cbbdccbbdbdddcbbbdb
ac
eeaeaaedbacdbeacbcbabbd
bebbcebbbddddcdddabebaed
daacaccebadbddbaedebdcaecbdee
ebeebeaecceebebdeeec
bbaedcaeadaebacadebacadbebabbaddcdceb
deeaaaecceaccebecccaececcdcdbbcbccdade
dbc
ebeabdeebbdbdcebdecbbdeccbabdcceacecbbc
bbbcadebadaaeeecbaacabedcbeae...

output:

4

result:

ok 1 number(s): "4"

Test #11:

score: 0
Accepted
time: 20ms
memory: 6828kb

input:

33333
knr
kmc
b
d
bmg
rej
fbn
ill
kdc
old
kpf
km
d
gjo
fod
ln
h
pdj
c
qfg
rci
o
eg
rp
n
eg
fig
ihn
h
om
nfg
cd
jhb
e
h
o
rpj
gd
h
lf
f
jb
h
qi
rq
n
km
o
ol
lpk
kp
gek
d
ebh
ch
ei
qm
hjh
eke
kb
djg
e
kl
ckk
m
k
fdr
ejr
m
q
md
bn
r
kf
gkn
nl
op
h
rcb
p
grr
cf
fq
dge
p
ioi
dk
f
pc
kdh
oqe
id
bfk
h
cpc
...

output:

3

result:

ok 1 number(s): "3"

Test #12:

score: 0
Accepted
time: 15ms
memory: 6444kb

input:

49999
cc
a
cb
a
d
c
cc
cc
bb
c
cc
d
dc
bd
cd
bb
bd
c
a
dc
d
cd
b
ab
dc
bb
cc
aa
c
c
ac
d
cb
d
c
a
b
b
ca
da
aa
d
bd
dc
c
b
bd
cc
a
a
cb
a
ad
d
a
bc
dc
a
bb
aa
b
bc
d
bb
c
cb
c
aa
ca
bd
da
ca
a
aa
b
ac
b
da
bd
cc
bb
a
aa
d
bc
ad
d
ca
a
c
b
ad
c
b
bd
c
b
a
d
ad
d
ac
c
cb
a
c
cc
bc
da
b
cd
cb
b
db
c
bb...

output:

2

result:

ok 1 number(s): "2"

Test #13:

score: 0
Accepted
time: 14ms
memory: 6664kb

input:

49999
hd
a
i
i
ig
gi
f
a
f
gh
ic
c
df
eg
cf
e
ei
e
ch
aa
c
dd
c
fh
fg
f
bh
eb
a
hf
e
fd
a
dg
ce
ed
i
h
c
h
g
b
g
e
gg
a
a
ee
a
hg
dh
db
gc
ci
ih
f
fc
ab
ce
f
e
b
i
c
fc
i
c
e
gh
f
de
h
e
cg
b
eb
b
ai
ei
fa
ci
i
e
ic
ab
c
de
gb
fi
dg
hh
ic
c
dc
hf
d
id
i
h
ab
c
h
bb
ca
e
g
g
gh
gh
i
ic
ie
f
b
bb
cd
c...

output:

2

result:

ok 1 number(s): "2"

Test #14:

score: 0
Accepted
time: 11ms
memory: 6680kb

input:

33333
eb
e
dg
b
d
b
bfa
fd
ga
g
ff
c
aeb
dd
ge
ace
cdc
f
gef
a
bdc
a
fbg
da
af
g
f
a
ab
bdd
cb
f
d
cdg
cc
e
eba
a
ef
af
fg
afb
da
fc
dfd
gcf
gd
e
c
b
b
gd
gcb
c
e
d
fe
bgc
f
gcc
bfe
ce
fc
d
deb
da
ffb
age
d
ebf
d
be
b
f
f
fda
d
cdd
d
da
bdb
acg
dcf
b
d
e
cea
e
ee
g
dab
fcd
ac
b
ac
gcg
f
e
ec
g
af
b
...

output:

3

result:

ok 1 number(s): "3"

Test #15:

score: 0
Accepted
time: 16ms
memory: 6560kb

input:

49999
ea
g
ig
ag
i
de
a
de
eg
e
e
db
g
h
a
dg
h
b
c
e
eh
c
e
i
gg
f
fd
g
fa
ed
ha
c
g
e
i
g
bd
c
f
gi
b
g
ca
fa
h
d
b
a
c
ed
i
b
g
h
i
i
ib
g
ie
e
bf
b
hg
a
ih
ei
cc
a
hi
g
f
dg
bd
c
ie
e
h
i
e
h
he
bb
ee
g
e
db
i
ii
i
f
eh
eg
i
h
dc
h
e
a
ga
c
h
d
d
hf
af
ef
a
h
f
d
hb
b
af
d
d
ic
e
a
cb
f
hi
id
g
...

output:

2

result:

ok 1 number(s): "2"