QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584178#6562. First LastBINYUWA 1ms3820kbC++142.3kb2024-09-23 09:55:532024-09-23 09:55:54

Judging History

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

  • [2024-09-23 09:55:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-09-23 09:55:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct Sqare
{
	int a[3][3];
	bool operator < (const Sqare &b) const
	{
		for(int i = 0;i < 3;i++)
			for(int j = 0;j < 3;j++)
				if(a[i][j] != b.a[i][j])
					return a[i][j] < b.a[i][j];
		return 0;
	}
}st;
int n,ans[3][3],cnt;
char c[25];
map <pair <Sqare,int> ,int> mp;
map <char,int> id;
int solve(Sqare st,int p)
{
	if(mp[{st,p}])return mp[{st,p}];
	int res = -1;
	for(int i = 0;i < 3;i++)
		if(st.a[p][i])
			st.a[p][i]--,
			res = max(res,-solve(st,i)),
			st.a[p][i]++;
	mp[{st,p}] = res;
	return res;
}
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s",c + 1);int m = strlen(c + 1);
		if(!id[c[1]])id[c[1]] = ++cnt;
		if(!id[c[m]])id[c[m]] = ++cnt;
		st.a[id[c[1]] - 1][id[c[m]] - 1]++;
	}
	Sqare now = st;
	for(int i = 0;i < 3;i++)
	{
		st.a[i][i] %= 2;
		for(int j = 0;j < i;j++)
		{
			int mn = min(st.a[i][j],st.a[j][i]);
			st.a[i][j] -= mn;st.a[j][i] -= mn;
		}
	}
	int mn = min(min(st.a[0][1],st.a[1][2]),st.a[2][0]);
	if(!mn)
	{
		swap(st.a[1][2],st.a[2][1]);
		swap(st.a[0][2],st.a[0][1]);
		swap(st.a[2][0],st.a[1][0]);
		swap(st.a[1][1],st.a[2][2]);
		swap(now.a[1][2],now.a[2][1]);
		swap(now.a[0][2],now.a[0][1]);
		swap(now.a[2][0],now.a[1][0]);
		swap(now.a[1][1],now.a[2][2]);
	}
	mn = min(min(st.a[0][1],st.a[1][2]),st.a[2][0]);
	if(mn <= 3)
	{
		for(int i = 0;i < 3;i++)
			for(int j = 0;j < 3;j++)
				if(st.a[i][j])
					st.a[i][j]--,
					ans[i][j] = solve(st,j),
					st.a[i][j]++;
				else
					st.a[j][i]++,
					ans[i][j] = solve(st,j),
					st.a[j][i]--;
		int sum = 0;
		for(int i = 0;i < 3;i++)
			for(int j = 0;j < 3;j++)
				if(ans[i][j] == -1)
					sum += now.a[i][j];
		cout<<sum<<"\n";
	}
	else
	{
		st.a[0][1] -= mn;st.a[1][2] -= mn;st.a[2][0] -= mn;
		int res = (mn * 3 + st.a[0][1] + st.a[1][2] + st.a[2][0]) % 2;
		st.a[0][0] = st.a[1][1] = st.a[2][2] = 0;
		for(int i = 0;i < 3;i++)
			for(int j = 0;j < 3;j++)
				if(st.a[i][j])
					st.a[i][j]--,
					ans[i][j] = solve(st,j),
					st.a[i][j]++;
				else
					st.a[j][i]++,
					ans[i][j] = solve(st,j),
					st.a[j][i]--;
		int sum = 0;
		for(int i = 0;i < 3;i++)
			for(int j = 0;j < 3;j++)
				if(ans[i][j] == -1&&res == 1)
					sum += now.a[i][j];
				else if(ans[i][j] == 1&&res == 0)
					sum += now.a[i][j];
		cout<<sum<<"\n";
	}
}

详细

Test #1:

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

input:

3
attic
climb
alpha

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

22
agora
alpha
antic
aorta
apnea
arena
aroma
attic
basic
blurb
china
circa
civic
climb
cobra
cocoa
comic
comma
conic
crumb
cubic
cynic

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3
ccabaabbba
acbbbacccb
ccccccacba

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

11
mraa
myga
vtwm
mala
vvgm
atvv
vusm
mznv
avea
atfv
amgv

output:

7

result:

ok single line: '7'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

1000
vznwivhoprv
pvzcjyruxv
phykv
vozinczup
vbp
vgjxfotuhzhobfp
pbv
vygphslv
vpnqrfep
vzrphpfggoqcgv
vgdjmzuckyedpnp
vatmaxfp
ppnmmwtqmv
paawwp
pspoycv
vcjthv
ppcvagp
pteiqdonkklp
vav
vcsxv
priqwbalidav
vinp
phqeijnqkgbxv
pwvmbivmgvouv
vwzhndzmqpcwkmp
pyzlv
vtvblfov
vrdv
vzrfmjdnaruwp
pfup
pwzv
vwyv...

output:

478

result:

ok single line: '478'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

1000
rlp
pgscawiivpjndlp
pxr
ruzutr
pqdhfniemqvvr
rvar
rp
prarwp
pkuinxempbmear
rupxuanwlvawmr
pp
rzfvr
rcsxoyirp
pgpilljr
pogeizvqlr
rajolbgzswur
rcap
ryzqymwr
rrpp
rbxtr
rfldblbesyhqr
rjidcekyrir
pqrycftr
rftwgmmakykkmep
pehkxkayuip
pguxsgtuikvp
rtxmynvoolrp
pzmsljlpcr
phcfdr
plaop
rydojaccp
pzfr
...

output:

246

result:

ok single line: '246'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

1000
ffn
fgikjn
fwtakdbjn
fsjnfzzn
feqmuasubirsf
faypin
fcsdhfjvncfzsn
nbcmvxemkan
ngoqtaaon
nlovkxxrbn
fhdqkltoxvif
fxpnqbguftsrhff
fyniukvsmlf
fibwbqckjpojglf
nwcvf
fxgeivnakggcn
nn
fkghlusecf
neuwdafrkzptwf
fcxn
ff
nlkxtn
fdlsijtpbcjjcbn
frlcjjnpsn
ntyabhf
nvf
fdlmlhebidazhn
fjn
fstxgnmfof
fqhusf...

output:

496

result:

ok single line: '496'

Test #8:

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

input:

15
adb
bdc
cda
aeb
bec
cea
afb
bfc
cfa
agb
bgc
cga
ahb
bhc
cha

output:

0

result:

wrong answer 1st lines differ - expected: '15', found: '0'