QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293066#4834. Trijectionucup-team1447#0 0ms0kbC++145.3kb2023-12-28 21:13:562023-12-28 21:13:57

Judging History

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

  • [2023-12-28 21:13:57]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-12-28 21:13:56]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#include<algorithm>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
	int x;cin>>x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 200005
#define inf 0x3f3f3f3f

namespace S0{
	
ull f[233];
void init(){
	f[0]=1;
	For(i,1,75){
		For(j,0,i-2) f[i]+=f[j]*f[i-j-2];
	//	cout<<"i: "<<i<<" "<<f[i]<<" "<<g[i]<<"\n";
	}
}

ull calc(string s){
	int n=s.size();
	if(n<=2)return 0;
	int pos=-1,tp=0;
	For(i,0,n-1){
		if(s[i]=='(')++tp;
		if(s[i]==')')--tp;
		if(tp==0){
			pos=i;
			break;
		}
	}
//	cout<<"pos: "<<s<<" "<<pos<<endl;
	string sl,sr;
	For(i,1,pos-1)sl+=s[i];
	For(i,pos+1,n-1)sr+=s[i];
	
	ull res=0;
	int cnt=sl.size();
	For(i,0,cnt-1) res+=f[i]*f[n-i-2];
	ull fl=calc(sl),fr=calc(sr);
	res+=fl*f[n-cnt-2]+fr;
	return res;
}

string build(ull x,int n){
	if(n==0)return "";
	if(n==2)return "()";
	For(i,0,n-2) if(i%2==0) {
		if(x<f[i]*f[n-i-2]){
			ull fl=x/f[n-i-2],fr=x%f[n-i-2];
			string sl=build(fl,i),sr=build(fr,n-i-2);
			return '('+sl+')'+sr;
		}else{
			x-=f[i]*f[n-i-2];
			continue;
		}
	}
	assert(0);
}

}

namespace S1{

int n,m;	
char mp[255][255];
bool in(int x,int y){
	return x>=1 && y>=1 && x<=n && y<=m && mp[x][y]=='#';
}
string work(){
	cin>>n>>m;
	For(i,1,n)cin>>(mp[i]+1);
	int x1=n,y1=1,x2=n,y2=1;
	string res;
	res+='(';
	For(_,1,n+m-2){
		if(in(x1,y1+1))++y1,res+='(';
		else --x1,res+=')';
		if(in(x2-1,y2))--x2,res+='(';
		else ++y2,res+=')';
	}
	res+=')';
//	cout<<"x1,y1,x2,y2 "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<"\n";
	return res;
}

int L[105],R[105];
void ins(int x,int y){
	L[x]=min(L[x],y);
	R[x]=max(R[x],y);
}
void build(string s){
	n=s.size();
	For(i,0,101) L[i]=inf,R[i]=-1;
	int x1=100,y1=1,x2=100,y2=1,p=1;
	ins(x1,y1);
	For(i,0,n/2-2){
		if(s[p]=='(')++y1;
		else --x1;
		++p,ins(x1,y1);
		if(s[p]=='(')--x2;
		else ++y2;
		++p,ins(x2,y2);
	//	cout<<"x1,y1,x2,y2 "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<"\n";
	}
//	cout<<"x1,y1,x2,y2 "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<"\n";
//	assert(x1==y1 && x2==y2);
	cout<<"poly"<<endl;
	cout<<100-x1+1<<" "<<y1<<endl;
	For(i,x1,100){
		For(j,1,y1){
			if(L[i]<=j && j<=R[i])cout<<"#";
			else cout<<".";
		}
		cout<<endl;
	}
}

}

namespace S2{

int a[maxn],n;
string work(){
	int mx=1;
	For(i,1,n)cin>>a[i];
	string res;
	For(i,1,n){
		if(a[i]>=mx){
		//	cout<<"i,mx,a[i] "<<i<<" "<<mx<<' '<<a[i]<<"\n";
			while(a[i]>mx)mx++,res+='(';
			res+='(',res+=')',++mx;
		}else{
			res+=')';
		}
	}
	return res;
}

bool vis[233];
void build(string s){
	n=s.size()/2;
	For(i,0,n*2)vis[i]=0;
	int mx=1,p=1,now=1;
	For(i,0,n*2-1){
		if(s[i]=='('){
			if(s[i+1]==')'){
				a[p++]=mx,vis[mx]=1;
				++mx,++i;
			}
			else ++mx;
		}else{
			while(vis[now])++now;
			a[p++]=now,++now;
		}
	}
	cout<<"perm"<<endl;
	For(i,1,p-1){
		cout<<a[i];
		if(i!=p)cout<<" ";
	}
	cout<<endl;
}

}

namespace S3{

int n;
bool g[105][105];

string solve(int l,int r){
//	cout<<"solve "<<l<<" "<<r<<"\n";
	if(l+1==r)return "";
	if(l+2==r)return "()";
	
	int mid=-1;
	For(i,l+1,r-1)
		if(g[l][i]&&g[i][r]){
			mid=i;
			break;
		}
	string fl=solve(l,mid),fr=solve(mid,r);
	return '('+fl+')'+fr;
}

string work(){
	For(i,0,n-1)For(j,0,n-1)g[i][j]=0;
	For(i,0,n-1) g[i][(i+1)%n]=g[(i+1)%n][i]=1;
	For(i,1,n-2){
		int u=read(),v=read(),w=read();
		--u,--v,--w;
		g[u][v]=g[v][u]=1;
		g[u][w]=g[w][u]=1;
		g[v][w]=g[w][v]=1;
	}
	return solve(0,n-1);
}


vector<array<int,3>>out;
void build(string s,int l,int r){
	if(!s.size())return;
	int pos=-1,n=s.size(),tp=0;
	For(i,0,n-1){
		if(s[i]=='(')++tp;
		if(s[i]==')')--tp;
		if(tp==0){
			pos=i;
			break;
		}
	}
	string sl,sr;
	For(i,1,pos-1)sl+=s[i];
	For(i,pos+1,n-1)sr+=s[i];
	int mid=l+1+sl.size()/2;
	out.pb({l,mid,r});
	build(sl,l,mid);
	build(sr,mid,r);
}
void build(string s){
	out.clear();
	build(s,1,n);
	sort(out.begin(),out.end());
	cout<<"triang"<<endl;
	for(auto [u,v,w]:out)cout<<u<<" "<<v<<" "<<w<<endl;
}

}

int n;
void qwq(){
	string opt;cin>>opt;
	if(opt=="poly"){
		ull x=S0::calc(S1::work());
		if(x&1) S2::build(S0::build(x,n*2));
		else S3::build(S0::build(x,n*2));
	}
	if(opt=="perm"){
		ull x=S0::calc(S2::work());
		if(x&1) S1::build(S0::build(x,n*2));
		else S3::build(S0::build(x^1,n*2));
	}
	if(opt=="triang"){
		ull x=S0::calc(S3::work());
		if(x&1) S2::build(S0::build(x^1,n*2));
		else S1::build(S0::build(x,n*2));
	}
}

signed main()
{
	S0::init();

//	string str; cin>>str;
//	ull x=S0::calc(str);
//	cout<<x<<"\n";
//	string str2=S0::build(x,str.size());
//	cout<<str2<<"\n";
	
//	S3::n=7;
//	S3::build("()(()())()");
//	string tmp=S3::work();
//	cout<<"tmp "<<tmp<<endl;
//	S3::build(tmp);
	int T;
	cin>>n>>T;
	S3::n=n+2;
	S2::n=n;
	
	For(_,1,T)qwq();
	return 0;
}
/*
encode
3
4
((((|)|)|)|)
5
(|(|))((|(|))|)

7 15 (kmax-n+4)
9 27
11 50-11
*/

詳細信息

Test #1:

score: 0
Wrong Answer on the first run

input:

5 4
poly
4 2
.#
##
##
#.
perm
4 1 5 2 3
triang
1 2 4
1 4 5
1 5 7
2 3 4
5 6 7
perm
2 1 3 5 4

output:

triang
1 2 7
2 3 4
2 4 5
2 5 7
5 6 7
poly
3 3
.##
###
###
poly
4 2
.#
##
##
##
poly
3 3
.##
.#.
##.

input:


output:


result:

wrong output format Expected integer, but "triang" found