QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763325#9558. The Devilas_lyrWA 2ms6604kbC++142.0kb2024-11-19 19:35:472024-11-19 19:35:48

Judging History

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

  • [2024-11-19 19:35:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6604kb
  • [2024-11-19 19:35:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 vl;
const int N=130;
const ll base=233327,inbase=960030343680757052,mod=(ll)1e18+3;
int n,m=128;
ll pw[N];
vector <int> e[N*N<<1];
char s[N];
ll hsh[N];
set <ll> st[N][N<<1];
map <ll,char> lst;
map <ll,int> mp;
ll to[N*N<<1];
int len[N*N<<1];
int nw;
int at[N*N<<1];
bool vis[N*N<<1];
bool dfs(int x){
	int mn=m*m;
	for(int y:e[x]){
		if(vis[y])
			continue;
		if(at[y]==0)
			mn=min(mn,len[y]);
	}
	for(int y:e[x]){
		if(vis[y])
			continue;
		vis[y]=1;
		if(len[y]<mn&&dfs(at[y])){
			at[x]=y;
			at[y]=x;
			return 1;
		}
		if(at[y]==0){
			at[x]=y;
			at[y]=x;
			return 1;
		}
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	nw=n;
	pw[0]=1;
	for(int i=1;i<=m;i++)
		pw[i]=(vl)pw[i-1]*base%mod;
	for(int T=1;T<=n;T++){
		for(int i=0;i<=m;i++)
			for(int j=0;j<=2*m;j++)
				st[i][j].clear();
		st[0][0].insert(0);
		int cnt=0;
		do{
			cnt++;
			scanf("%s",s+1);
			int len=strlen(s+1);
			for(int i=1;i<=len;i++)
				hsh[i]=((vl)hsh[i-1]*base+s[i])%mod;
			int ct=0;
			for(int i=1;ct<m&&i<=2*m;i++){
				for(int j=1;ct<m&&j<=len&&j<=i;j++){
					for(ll x:st[cnt-1][i-j]){
						ll res=((vl)x*pw[j]+hsh[j])%mod;
						if(lst.find(res)==lst.end())
							lst[res]=s[j];
						if(st[cnt][i].find(res)==st[cnt][i].end()){
							st[cnt][i].insert(res);
							if(++ct==m)
								break;
						}
					}
				}
			}
		}while(getchar()==' ');
		for(int i=0;i<=2*m;i++){
			for(ll x:st[cnt][i]){
				if(mp.find(x)==mp.end()){
					mp[x]=++nw;
					to[nw]=x;
					len[nw]=i;
				}
				e[T].push_back(mp[x]);
			}
		}
	}
	for(int x=1;x<=n;x++){
		for(int i=1;i<=nw;i++)
			vis[i]=0;
		if(dfs(x)==0){
			puts("no solution");
			return 0;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ll x=to[at[i]];
		string pr;
		while(x){
			pr+=lst[x];
			x-=lst[x];
			if(x<0)
				x+=mod;
			x=(vl)x*inbase%mod;
			ans++;
		}
		reverse(pr.begin(),pr.end());
		cout<<pr<<'\n';
	}
	printf("%d",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 6604kb

input:

5
automated teller machine
active teller machine
active trouble maker
always telling misinformation
American Teller Machinery

output:

atem
actm
atma
atm
ATM
18

result:

wrong output format Extra information in the output file