QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627136#7882. Linguistics Puzzlefrankly6WA 0ms3588kbC++172.4kb2024-10-10 14:54:122024-10-10 14:54:15

Judging History

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

  • [2024-10-10 14:54:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-10-10 14:54:12]
  • 提交

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; ch[d]=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);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
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:


result:

wrong answer invalid character