QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627241#7882. Linguistics Puzzlefrankly6RE 0ms3832kbC++173.0kb2024-10-10 15:17:082024-10-10 15:17:09

Judging History

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

  • [2024-10-10 15:17:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3832kb
  • [2024-10-10 15:17:08]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
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];
vector<string> tar;
char ch[52];
map<char,int> mp;
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;
}
char ti(int a) {return (a<=25)?a+'a':a+'A'-26;}
int tr(char c) {return (c<='z')?c-'a':c-'A'+26;}
void upd(char ch, int opt)
{
    int id=tr(ch);
    if(opt==1) t1[id]++;
    if(opt==2) t2[id]++;
    if(opt==3) t3[id]++;
}
bool ck()
{
    vector<int> tmp, tmp2;
    tmp.clear();
    for(auto s:tar)
    {
        if(s.size()==2) tmp.emplace_back(mp[s[0]]*N+mp[s[1]]);
        else tmp.emplace_back(mp[s[0]]);
    }
    sort(tmp.begin(),tmp.end());
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            tmp2.emplace_back(i*j);
    if(tmp!=tmp2) return 0;
    return 1;
}
bool dfs(int d)
{
    if(d==N) return ck();
    for(auto u:v[d])
    {
        if(vis[u]) continue;
        if(!tag)
        {
            vis[u]=1; ch[d]=ti(u); mp[ti(u)]=d;
            if(dfs(d+1)) return 1;
            vis[u]=0;
        }
    }
    return 0;
}
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();
        tar.clear();
        mp.clear();
        for(int i=1;i<=N*N;i++)
        {
            string s; cin >> s;
            tar.emplace_back(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: 3832kb

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: 3796kb

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
Runtime Error

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
pvutsrhwoimlnjkqgfedbca
xbvuts...

result: