QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143313#7016. SockpuppetsSorting#AC ✓142ms13996kbC++204.2kb2023-08-21 01:51:022023-08-21 01:51:04

Judging History

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

  • [2023-08-21 01:51:04]
  • 评测
  • 测评结果:AC
  • 用时:142ms
  • 内存:13996kb
  • [2023-08-21 01:51:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define fi first
#define se second
int n,m;
int sz=1;
int ch[100001][26];
int l[100001],r[100001];
const int iu=26;
typedef array<ll,221> arin;
const int winter=220;
arin one;
array<int,3>hs[221];
int unh[11][11][11];
ll C[11][11];
void pre(){
	one[1]=1;
	int ptr=0;
	for(int i=0; i<=9 ;i++){
		for(int j=0; i+j<=9 ;j++){
			for(int k=0; i+j+k<=9 ;k++){
				hs[++ptr]={i,j,k};
				unh[i][j][k]=ptr;
			}
		}
	}
	C[0][0]=1;
	for(int i=1; i<=10 ;i++){
		C[i][0]=1;
		for(int j=1; j<=i ;j++){
			C[i][j]=C[i-1][j-1]+C[i-1][j];
		}
	}
}
vector<arin>v;
arin merge(arin &x,arin &y,int hl,int hr){
	arin z;
	for(int i=0; i<winter ;i++) z[i]=0;
	for(int i1=0; i1<=hl ;i1++){
		for(int i2=0; i1+i2<=hl ;i2++){
			for(int k1=0; k1<=hr ;k1++){
				for(int k2=0; k2<=hr ;k2++){
					for(int j1=0; i1+i2+j1<=hl ;j1++){
						for(int j2=0; i1+i2+j2<=hl ;j2++){
							for(int j3=min(j1,j2); i1+i2+j1+j2-j3<=hl && j3>=0 ;j3--){
								int idx=unh[i1][j1][k1];
								int idy=unh[i2][j2][k2];
								int idz=unh[i1+i2+j3][j1+j2-j3-j3][k1+k2];
								ll ways=C[i1+i2+j3][j3]*C[i1+i2][i1]*C[j1+j2-j3-j3][j1-j3]*C[k1+k2][k1];
								z[idz]=(z[idz]+x[idx]*y[idy]%mod*ways)%mod;
							}
						}
					}
				}
			}
		}
	}
	return z;
}
int cal(int id,int hl,int hr){
	//cout << id << ' ' << l[id] << ' ' << r[id] << endl;
	vector<int>e;
	for(int i=0; i<26 ;i++){
		if(ch[id][i]!=0) e.push_back(ch[id][i]);
	}
	if(e.size()==1 && l[id]==0 && r[id]==0) return cal(e[0],hl,hr);
	arin cur=one;
	bool f=true;
	for(auto c:e){
		int res=cal(c,hl+l[id],hr+r[id]);
		if(f){
			f=false;
			cur=v[res];
		}
		else{
			cur=merge(cur,v[res],hl+l[id],hr+r[id]);
		}
	}/*
	for(int i=0; i<=1 ;i++){
		for(int j=0; j<=1 ;j++){
			for(int k=0; k<=1 ;k++){
				cout << "sexc " << id << ' ' << cur[unh[i][j][k]] << ' ' << i << ' ' << j << ' ' << k << endl;
			}
		}
	}*/
	if(l[id]!=0){
		arin z;
		for(int i=0; i<winter ;i++) z[i]=0;
		for(int i=0; i<=hl ;i++){
			for(int j=0; i+j<=hl ;j++){
				for(int k=0; k<=hr ;k++){
					int idz=unh[i][j][k];
					if(k>=2){//both alr used
						int idy=unh[i][j][k-2];
						ll ways=k*(k-1)/2;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					if(k>=1){//one used one keep
						int idy=unh[i][j+1][k-1];
						ll ways=k;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					if(k>=1){//one used one discard
						int idy=unh[i][j][k-1];
						ll ways=k;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					
					{
						int idy=unh[i+1][j][k];
						ll ways=1;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					{
						int idy=unh[i][j+1][k];
						ll ways=1;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					{
						int idy=unh[i][j][k];
						ll ways=1;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
				}
			}
		}
		v.push_back(z);
	}
	else if(r[id]!=0){
		arin z;
		for(int i=0; i<winter ;i++) z[i]=0;
		for(int i=0; i<=hl ;i++){
			for(int j=0; i+j<=hl ;j++){
				for(int k=0; k<=hr ;k++){
					int idz=unh[i][j][k];
					if(i>=1){
						int idy=unh[i-1][j+1][k];
						ll ways=i;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					if(j>=1){
						int idy=unh[i][j-1][k];
						ll ways=j;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					{//not yet used
						int idy=unh[i][j][k+1];
						ll ways=1;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
					}
					{//unused
						int idy=unh[i][j][k];
						ll ways=1;
						z[idz]=(z[idz]+cur[idy]*ways)%mod;
						
					}
				}
			}
		}
		v.push_back(z);
	}
	else{
		v.push_back(cur);
	}
	return v.size()-1;
}
void solve(int rr){
	v.clear();
	cin >> n >> m;
	sz=1;
	for(int i=0; i<iu ;i++) ch[sz][i]=0;
	l[sz]=r[sz]=0;
	for(int i=1; i<=n+m ;i++){
		string s;cin >> s;
		int cur=1;
		int cl=(i<=n);
		int cr=1-cl;
		for(auto c:s){
			if(ch[cur][c-'a']==0){
				ch[cur][c-'a']=++sz;
				for(int i=0; i<iu ;i++) ch[sz][i]=0;
				l[sz]=r[sz]=0;
			}
			cur=ch[cur][c-'a'];
		}
		l[cur]+=cl;r[cur]+=cr;
	}
	int res=cal(1,0,0);
	cout << "Case #" << rr << ": " << v[res][1] << '\n';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	pre();
	int t;cin >> t;
	for(int i=1; i<=t ;i++) solve(i);
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 2
a
aa
aaa
1 2
aa
a
ab
5 5
a
ah
ahd
ahdo
ahdoc
ahdoca
ahdocah
ahdocahd
ahdocahdo
ahdocahdoc

output:

Case #1: 4
Case #2: 2
Case #3: 6396

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 142ms
memory: 13996kb

input:

100
10 10
fvwuvmqas
stfwxm
ubxiothqft
tuej
pqdbhweemy
ahugzphgdd
zxujab
fgolj
clnt
hknzgpuox
jtlhg
pidr
nvnoz
grjswk
axukzzsmif
x
o
gru
efoyeuaka
idlknkz
10 10
hbyex
xybxlct
zydcjvixu
vyoppkp
mcevplgemi
zkcqyswwf
gcp
brrzngdbfo
kzghf
honutkms
qxk
ct
axmtzky
wctky
ccuyhxx
ochzlppomh
nfls
svhgtfwq
whl...

output:

Case #1: 1
Case #2: 1
Case #3: 1
Case #4: 8
Case #5: 4
Case #6: 4
Case #7: 4
Case #8: 1
Case #9: 2
Case #10: 1
Case #11: 1
Case #12: 1
Case #13: 1
Case #14: 2
Case #15: 1
Case #16: 2
Case #17: 4
Case #18: 1
Case #19: 4
Case #20: 2
Case #21: 45847834
Case #22: 639535370
Case #23: 707182876
Case #24: ...

result:

ok 100 lines