QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#273573#7882. Linguistics Puzzleucup-team1134#RE 1ms3592kbC++233.8kb2023-12-03 01:42:342023-12-03 01:42:34

Judging History

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

  • [2023-12-03 01:42:34]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3592kb
  • [2023-12-03 01:42:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int Q;cin>>Q;
    while(Q--){
        int n;cin>>n;
        
        vector<int> ONE(n),A(n),B(n);
        for(int a=0;a<n;a++){
            for(int b=0;b<n;b++){
                int x=a*b;
                if(x<n) ONE[x]++;
                else{
                    A[x/n]++;
                    B[x%n]++;
                }
            }
        }
        
        map<tuple<int,int,int>,vector<int>> MA;
        for(int i=0;i<n;i++){
            MA[{ONE[i],A[i],B[i]}].push_back(i);
        }
        
        for(int i=0;i<n;i++){
            ONE[i]=0;
            A[i]=0;
            B[i]=0;
        }
        vector<string> T;
        for(int i=0;i<n*n;i++){
            string S;cin>>S;
            T.push_back(S);
            if(si(S)==1){
                int x;
                if(S[0]<='z') x=(int)(S[0]-'a');
                else x=(int)(S[0]-'A')+26;
                
                ONE[x]++;
            }else{
                int x,y;
                if(S[0]<='z') x=(int)(S[0]-'a');
                else x=(int)(S[0]-'A')+26;
                
                if(S[1]<='z') y=(int)(S[1]-'a');
                else y=(int)(S[1]-'A')+26;
                
                A[x]++;
                B[y]++;
            }
        }
        sort(all(T));
        
        auto check=[&](string X){
            vector<string> U;
            for(int a=0;a<n;a++){
                for(int b=0;b<n;b++){
                    int x=a*b;
                    string ad;
                    
                    if(x<n) ad+=X[x];
                    else{
                        ad+=X[x/n];
                        ad+=X[x%n];
                    }
                    
                    U.push_back(ad);
                }
            }
            
            sort(all(U));
            
            return (U==T);
        };
        
        while(1){
            for(auto &x:MA){
                if(si(x.se)==2){
                    if(rng()%2) swap(x.se[0],x.se[1]);
                }
            }
            
            string ans(n,'.');
            
            map<tuple<int,int,int>,int> nex;
            for(int i=0;i<n;i++){
                int x=MA[{ONE[i],A[i],B[i]}][nex[{ONE[i],A[i],B[i]}]];
                nex[{ONE[i],A[i],B[i]}]++;
                if(i<26) ans[x]=char('a'+i);
                else ans[x]=char('A'+(i-26));
            }
            
            if(check(ans)){
                cout<<ans<<"\n";
                break;
            }
        }
    }
    
    /*
    for(int n=2;n<=52;n++){
        vector<int> ONE(n),A(n),B(n);
        for(int a=0;a<n;a++){
            for(int b=0;b<n;b++){
                int x=a*b;
                if(x<n) ONE[x]++;
                else{
                    A[x/n]++;
                    B[x%n]++;
                }
            }
        }
        map<tuple<int,int,int>,int> SE;
        for(int i=0;i<n;i++){
            SE[{ONE[i],A[i],B[i]}]++;
            //cout<<ONE[i]<<" "<<A[i]<<" "<<B[i]<<endl;
        }
        //cout<<endl;
        
        for(auto [a,b]:SE) cout<<b<<endl;
        if(n!=si(SE)) cout<<n<<" "<<si(SE)<<endl;
    }
    */
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

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

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:


result: