QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584182 | #6562. First Last | BINYU | WA | 0ms | 3720kb | C++14 | 2.3kb | 2024-09-23 09:58:14 | 2024-09-23 09:58:15 |
Judging History
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] = 0 - 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] = 0 - 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";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
3 attic climb alpha
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
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:
15
result:
wrong answer 1st lines differ - expected: '6', found: '15'