QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276394#7882. Linguistics Puzzle___TL 0ms3496kbC++983.7kb2023-12-05 20:47:032023-12-05 20:47:04

Judging History

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

  • [2023-12-05 20:47:04]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3496kb
  • [2023-12-05 20:47:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 55

multimap<pair<pair<pair<int,int>,int>,pair<vector<int>,vector<int> > >,int>q;

pair<char,char>s[N*N];
pair<pair<int,int>,int>add[N],cnt[N];
map<int,int>adq1[N],adq2[N],cnq1[N],cnq2[N];
vector<int>adv1[N],adv2[N],cnv1[N],cnv2[N];
char ch[5];
int n;
int cti(char ch){
    if(islower(ch))return ch-'a';
    else return ch-'A'+26;
}
char itc(int ch){
    if(ch<26)return ch+'a';
    else return ch-26+'A';
}
char res[N];
int main(){
    //freopen("1.in","r",stdin);
    int t;cin>>t;
    while(t--){
        cin>>n;
        for(int i=0;i<=n*n;i++){
            s[i].first=s[i].second='\0';
            add[i].first.first=add[i].first.second=add[i].second=0;
            cnt[i].first.first=cnt[i].first.second=cnt[i].second=0;
            adq1[i].clear();adq2[i].clear();cnq1[i].clear();cnq2[i].clear();
            adv1[i].clear();adv2[i].clear();cnv1[i].clear();cnv2[i].clear();
        }
        q.clear();
        for(int i=1;i<=n*n;i++){
            cin>>ch;
            if(!isalpha(ch[1])){
                s[i].second=ch[0];
                s[i].first='\0';
            }else{
                s[i].second=ch[1];
                s[i].first=ch[0];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                int p=i*j;
                int x=p/n,y=p%n;
                if(x>0){
                    cnt[x].first.first++;
                    cnt[y].first.second++;
                    if(cnq1[x].find(y)==cnq1[x].end())cnq1[x].insert(make_pair(y,1));
                    else cnq1[x][y]++;
                    if(cnq2[y].find(x)==cnq2[y].end())cnq2[y].insert(make_pair(x,1));
                    else cnq2[y][x]++;
                }else{
                    cnt[y].second++;
                }
            }
        }
        for(int i=1;i<=n*n;i++){
            int x=cti(s[i].first),y=cti(s[i].second);
            if(s[i].first!='\0'){
                add[x].first.first++;
                add[y].first.second++;
                if(adq1[x].find(y)==adq1[x].end())adq1[x].insert(make_pair(y,1));
                else adq1[x][y]++;
                if(adq2[y].find(x)==adq2[y].end())adq2[y].insert(make_pair(x,1));
                else adq2[y][x]++;
            }else{
                add[y].second++;
            }
        }
        for(int i=0;i<n;i++){
            for(map<int,int>::iterator it=adq1[i].begin();it!=adq1[i].end();it++)if(it->second!=0)
                adv1[i].push_back(it->second);
            for(map<int,int>::iterator it=adq2[i].begin();it!=adq2[i].end();it++)if(it->second!=0)
                adv2[i].push_back(it->second);   
            sort(adv1[i].begin(),adv1[i].end());
            sort(adv2[i].begin(),adv2[i].end());
        }
        for(int i=0;i<n;i++){
            for(map<int,int>::iterator it=cnq1[i].begin();it!=cnq1[i].end();it++)if(it->second!=0)
                cnv1[i].push_back(it->second);
            for(map<int,int>::iterator it=cnq2[i].begin();it!=cnq2[i].end();it++)if(it->second!=0)
                cnv2[i].push_back(it->second);
            sort(cnv1[i].begin(),cnv1[i].end());
            sort(cnv2[i].begin(),cnv2[i].end());    
        }
        for(int i=0;i<n;i++)
            q.insert(make_pair(make_pair(add[i],make_pair(adv1[i],adv2[i])),i));
        for(int i=0;i<n;i++){
            multimap<pair<pair<pair<int,int>,int>,pair<vector<int>,vector<int> > >,int>::iterator
                it=q.find(make_pair(cnt[i],make_pair(cnv1[i],cnv2[i])));
            res[i]=it->second;
            q.erase(it);
        }
        for(int i=0;i<n;i++)cout<<itc(res[i]);
        cout<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3496kb

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

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
Time Limit Exceeded

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

result: