QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294649#4825. Even and Odd Combinationsucup-team1525#0 0ms0kbC++202.1kb2023-12-30 15:20:412023-12-30 15:20:42

Judging History

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

  • [2023-12-30 15:20:42]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-12-30 15:20:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=100;
ll f[N+5];
void prep(){
    f[0]=1;
    for(int i=1;i<=25;i++)
        for(int j=0;j<i;j++)
            for(int k=0;j+k<i;k++)
                f[i]+=f[j]*f[k]*f[i-j-k-1];
    // printf("%lld\n",f[N]);
}
ll dfs(int n,string s){
    if(n==0) return 0;
    int j=0,k=0,mt=0,cnt=0;
    for(int i=0;i<n*3;i++)
        if(s[i]=='(') mt++;
        else if(s[i]==')'){
            mt--;
            if(!mt){
                k=cnt; break;
            }
            cnt++;
        }
        else{
            if(mt==1) j=cnt;
        }
    ll res=0;
    for(int j1=0;j1<j;j1++)
        for(int k1=0;j1+k1<n;k1++)
            res+=f[j1]*f[k1]*f[n-1-j1-k1];
    for(int k1=0;j+k1<k;k1++)
        res+=f[j]*f[k1]*f[n-1-j-k1];
    string t="";
    for(int i=1;i<=j*3;i++) t+=s[i];
    res+=dfs(j,t)*f[k]*f[n-1-k];
    t="";
    for(int i=j*3+2;i<3*k+2;i++) t+=s[i];
    res+=dfs(k-j,t)*f[n-1-k];
    t="";
    for(int i=3*k+3;i<3*n;i++) t+=s[i];
    res+=dfs(n-1-k,t);
    return res;
}
void encode(){
    int n;
    string s;
    scanf("%d",&n);
    cin>>s;
    printf("%lld\n",dfs(n,s));
}
string dfs(int n,ll res){
    if(n==0) return {};
    for(int j=0;j<n;j++)
        for(int k=0;j+k<n;k++){
            ll tmp=f[j]*f[k]*f[n-j-k-1];
            if(tmp<res) res-=tmp;
            else{
                string ans="(";
                // printf("%d %d %d\n",n,j,k);
                ans+=dfs(j,res/(f[k]*f[n-j-k-1]))+"|";
                res%=f[k]*f[n-j-k-1];
                ans+=dfs(k,res/f[n-j-k-1])+")";
                res%=f[n-j-k-1];
                ans+=dfs(n-1-j-k,res);
                return ans;
            }
        }
    assert(0);
}
void decode(){
    int n; ll res;
    scanf("%d",&n);
    scanf("%lld",&res);
    cout<<dfs(n,res)<<endl;
}
int main(){
    prep();
    char s[10];
    scanf("%s",s);
    if(s[0]=='e'){
        int t; scanf("%d",&t);
        while(t--) encode();
    }
    else{
        int t; scanf("%d",&t);
        while(t--) decode();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer on the first run

input:

6
3 0
2 1
1
3 3
1 2 3
3 1
1
3 1
2
3 1
3

output:


(|)
(|)(|)(|)

input:


output:


result:

wrong output format Expected integer, but "(|)" found (test case 1)