QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#641510 | #7882. Linguistics Puzzle | FreeTimeLove | WA | 6ms | 3872kb | C++14 | 3.0kb | 2024-10-14 20:52:15 | 2024-10-14 20:52:16 |
Judging History
answer
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=55;
inline int rd(){
int d=1,k=0;char c=getchar();
while(!(c>='0' and c<='9' or c=='-'))c=getchar();if(c=='-')d=-1,c=getchar();
while(c>='0' and c<='9')k=(k<<3)+(k<<1)+(c^48),c=getchar();
return d*k;
}
const int mod=998244353;
int n,to[200],a[N],s0[N*N][2];
char s[N*N][3],ch[N],b[N],ans[N];
//ll hs[N*N][N],hs1[N*N][N];
ll hs[N][N],hs1[N][N];
int c[N],c0[N][N];
int c1[N],c10[N][N];
int K;
void dac(int l,int r,int KK){
if(l>=r)re;
K=KK;
sort(b+l,b+r+1,[](char x,char y){re hs[K][to[x]]<hs[K][to[y]];});
sort(a+l,a+r+1,[](int x,int y){re hs1[K][x]<hs1[K][y];});
ll nw=-1;
int la=l-1;
for(int i=l;i<=r;i++){
if(i==r||(hs[K][to[b[i]]]!=hs[K][to[b[i+1]]])&&(hs1[K][a[i]]!=hs1[K][a[i+1]])){
dac(la+1,i,KK+1);
la=i;
}
}
}
signed main(){
// freopen("data.in","r",stdin);
int T=rd();
for(int i=0;i<26;i++)to[i+'a']=i,ch[i]='a'+i,to[i+'A']=i+26,ch[i+26]='A'+i;
while(T--){
n=rd();
memset(c0,0,sizeof c0),memset(c,0,sizeof c);
memset(c10,0,sizeof c10),memset(c1,0,sizeof c1);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
int x=i*j/n,y=i*j%n;
if(x)c10[x][y]++;
else c1[y]++;
}
for(int i=n*n-1;i>=0;i--){
scanf("%s",s[i]);
if(s[i][1])++c0[to[s[i][0]]][to[s[i][1]]];
else ++c[to[s[i][0]]];
}
for(int i=0;i<n;i++){
hs[0][i]=c[i]*c[i];
for(int j=0;j<n;j++)hs[0][i]+=c0[i][j]*c0[i][j]*1;
for(int j=0;j<n;j++)hs[0][i]+=c0[j][i]*c0[i][j]*2;
hs1[0][i]=c1[i]*c1[i];
for(int j=0;j<n;j++)hs1[0][i]+=c10[i][j]*c10[i][j]*1;
for(int j=0;j<n;j++)hs1[0][i]+=c10[j][i]*c10[i][j]*2;
}
for(int k=1;k<=50;k++){
for(int i=0;i<n;i++){
hs[k][i]=c[i]*c[i];
for(int j=0;j<n;j++)hs[k][i]+=hs[k-1][j]*c0[i][j]*c0[i][j]*1;
for(int j=0;j<n;j++)hs[k][i]+=hs[k-1][j]*c0[j][i]*c0[i][j]*2;
hs[k][i]%=mod;
hs1[k][i]=c1[i]*c1[i];
for(int j=0;j<n;j++)hs1[k][i]+=hs1[k-1][j]*c10[i][j]*c10[i][j]*1;
for(int j=0;j<n;j++)hs1[k][i]+=hs1[k-1][j]*c10[j][i]*c10[i][j]*2;
hs1[k][i]%=mod;
}
}
for(int i=0;i<n;i++)a[i]=i,b[i]=ch[i];
dac(0,n-1,0);
for(int i=0;i<n;i++)ans[a[i]]=b[i];
ans[n]=0;
printf("%s\n",ans);
}
re 0;
}
/*
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
*/
}signed main(){re FRTMLV::main();}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
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: 3872kb
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: 6ms
memory: 3844kb
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 iqmonhckjrpgfedlba prisodmbkjqghfencla tcrdpoaklmjihfgeqsbn utiraponmlksghjfecdbq qotsrvjunmlkpiegfhdcba pvutsrhwoimlkjngqfedbca xbvuts...
result:
wrong answer The product 5*6=30 is not in the output at case #16