QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618232#4824. Bracket-and-bar Sequenceslichenyu_ac0 0ms0kbC++141.7kb2024-10-06 20:02:372024-10-06 20:02:38

Judging History

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

  • [2024-10-06 20:02:38]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-06 20:02:37]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=110;

ll f[N];

namespace encode{

	ll solve(int n,string s){
		if(!n)return 0;
		int l=0,mid=0,r=0;
		int top=0;
		for(int i=0;;i++){
			top+=(s[i]=='(');
			top-=(s[i]==')');
			if(top==1&&s[i]=='|')mid=i;
			if(!top){
				r=i;
				break;
			}
		}
		ll cnt1=(mid-l-1)/3,cnt2=(r-mid-1)/3,cnt3=(n*3-r-1)/3;
		ll val=0;
		for(int i=0;i<n;i++)
			for(int j=0;i+j<n;j++)
				if(i==cnt1&&j==cnt2)
					return val+(solve(cnt1,s.substr(l+1,cnt1*3))*f[cnt2]+solve(cnt2,s.substr(mid+1,cnt2*3)))*f[cnt3]+solve(cnt3,s.substr(r+1,cnt3*3));
				else val+=f[i]*f[j]*f[n-1-i-j];
		return -1;
	}

	void solve(){
		int n;string s;
		cin>>n>>s;
		cout<<solve(n,s);
	}

	int main(){
		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-1-j-k];
		int T;
		cin>>T;
		while(T--)solve();
		return 0;
	}
}

namespace decode{

	string solve(int n,ll s){
		// cerr<<n<<s<<endl;
		if(!n)return "";
		for(int i=0;i<n;i++)
			for(int j=0;i+j<n;j++)
				if(s<f[i]*f[j]*f[n-1-i-j]){
					ll cnt3=s%f[n-1-i-j];
					ll cnt2=(s/f[n-1-i-j])%f[j];
					ll cnt1=s/f[n-1-i-j]/f[j];
					return "("+solve(i,cnt1)+"|"+solve(j,cnt2)+")"+solve(n-1-i-j,cnt3);
				}else s-=f[i]*f[j]*f[n-1-i-j];
		return "-1";
	}

	void solve(){
		int n;ll s;
		cin>>n>>s;
		cout<<solve(n,s)<<endl;
	}

	int main(){
		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-1-j-k];
		int T;
		cin>>T;
		while(T--)solve();
		return 0;
	}
}

int main(){
    string s;
    cin>>s;
    if(s=="encode")encode::main();
    else decode::main();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer on the first run

input:

encode
3
1
(|)
4
((((|)|)|)|)
5
(|(|))((|(|))|)

output:

05465

input:


output:


result:

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