QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627139 | #7882. Linguistics Puzzle | frankly6 | WA | 8ms | 3788kb | C++17 | 2.4kb | 2024-10-10 14:55:04 | 2024-10-10 14:55:05 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int MX=52;
int T, N, tag=0;
int t1[MX], t2[MX], t3[MX];
bool vis[MX];
vector<int> v[MX];
char ch[52];
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
void upd(char ch, int opt)
{
int id=0;
if(ch>='a'&&ch<='z') id=ch-'a';
else if(ch>='A'&&ch<='Z') id=ch-'A'+26;
if(opt==1) t1[id]++;
if(opt==2) t2[id]++;
if(opt==3) t3[id]++;
}
void dfs(int d)
{
if(d==N){tag=1;return;}
for(auto u:v[d])
{
if(vis[u]) continue;
if(!tag)
{
vis[u]=1; ch[d]=(u<=25)?u+'a':u+'A'-26;
dfs(d+1);
vis[u]=0;
}
}
return;
}
int main()
{
// freopen("testdata.in","r",stdin);
T=read();
while(T--)
{
N=read();
tag=0;
memset(ch,0,sizeof(ch));
memset(vis,0,sizeof(vis));
memset(t1,0,sizeof(t1));
memset(t2,0,sizeof(t2));
memset(t3,0,sizeof(t3));
for(int i=0;i<52;i++) v[i].clear();
for(int i=1;i<=N*N;i++)
{
string s; cin >> s;
// cout << s << '\n';
if(s.size()==2)
{
if(s[0]==s[1]) upd(s[0],3);
else upd(s[0],1), upd(s[1],2);
}
else upd(s[0],2);
}
for(int num=0;num<N;num++)
{
int n1=0, n2=0, n3=0;
for(int i=0;i<N;i++)
{
for(int j=0;j<N;j++)
{
int now=i*j;
if(now>=N)
{
if(now%N==num&&now/N==num) n3++;
else if(now%N==num) n2++;
else if(now/N==num) n1++;
}
else if(now==num) n2++;
}
}
// cout << "num=" << num << ", n=" << n1 << " " << n2 << " " << n3 << '\n';
for(int i=0;i<N;i++)
{
if(t1[i]==n1&&t2[i]==n2&&t3[i]==n3)
{
v[num].emplace_back(i);
}
}
}
dfs(0);
for(int i=0;i<N;i++) cout << ch[i]; cout << '\n';
}
return (0-0);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
2 3 a b a b b b b c cc 4 d d d d d c b a d b cd cb d a cb bc
output:
bca dcba
result:
ok OK
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
2 4 d a a bc ba bc b a a a d a a cb c c 4 a b da b b d ad b db b a c da b c b
output:
abcd bdac
result:
ok OK
Test #3:
score: -100
Wrong Answer
time: 8ms
memory: 3788kb
input:
50 3 b b b a a c b b cc 4 d ab c ad d b ba ab c b d d d d d a 5 a aa aa ab ab ae b b e c c c ba c c c c dd d d dd c e c e 6 a ca a a a a a a ce a a b ba ba bc bc bd be e c c ca a cd cd be d d dc dc e e a eb f f 7 a a a a a a a a cf a a a a b b b b c c c cf a dd d dc d dd e f ed ee ee fb eg eg eg eg ...
output:
bca dabc cadbe abcdef aefdcgb fcheabgd bhgfedcia jhcgfideba fjbadkegcih klhgjbaedcif igkjmclfedhba nflijahgmbdcek anmlfijbgkhdceo nofmlkjchdbegipa aponblgjihcfqdkme iqmonhckfrpgjedlba prisodmbkjqghfencla tcrdpoaklmjihfgeqsbn utiraponmlksghjfecdbq qotsrvjunmlkpiegfhdcba pvutsrhwoimlkjnqgfedbca xbvuts...
result:
wrong answer The product 3*15=45 is not in the output at case #27