QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#730846#5311. Master of BothHobertWA 0ms3852kbC++201.2kb2024-11-09 21:57:582024-11-09 21:57:58

Judging History

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

  • [2024-11-09 21:57:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-11-09 21:57:58]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N=1e6+10;

struct Tree{
	int to[27];
	int cnt[27];
}tr[N];

int idx=1;
map<pair<char,char>,int>mp;


void build(int u,string s,int i){
	int c=s[i]-'`';
	for(int j=0;j<27;j++){
		if(j!=c&&tr[u].to[j]){
			mp[{c+'`',j+'`'}]+=tr[u].cnt[j];
		}
	}
	if(!tr[u].to[c]){
		tr[u].to[c]=idx;
		for(int j=0;j<27;j++) tr[idx].to[j]=tr[idx].cnt[j]=0;
		idx++;
	}
	tr[u].cnt[c]++;
	if(i<(int)s.size()) build(tr[u].to[s[i]-'`'],s,i+1);
}

void solve(){
	int n,q;
	cin>>n>>q;
	vector<string>v(n);
	for(auto &x:v) cin>>x;
	for(int j=0;j<26;j++) tr[0].to[j]=tr[0].cnt[j]=0;
	
	for(int i=n-1;i>=0;i--){
		v[i]+='`';
		build(0,v[i],0);
//		cout<<v[i]<<endl;
//		for(auto [x,y]:mp){
//			auto [a,b]=x;
//			if(y) cout<<a<<b<<' '<<y<<endl;
//		}
	}
	
//	for(auto [x,y]:mp){
//		auto [a,b]=x;
//		if(y) cout<<a<<b<<' '<<y<<endl;
//	}
	while(q--){
		string s;
		cin>>s;
		s='`'+s;
		int res=0;
		for(int i=0;i<27;i++){
			for(int j=0;j<=i;j++){
				res+=mp[{s[i],s[j]}];
			}
		}
		cout<<res<<endl;
	}
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
	while(_--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3852kb

input:

5 3
aac
oiputata
aaa
suikabudada
aba
abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
aquickbrownfxjmpsvethlzydg

output:

4
4
4

result:

wrong answer 2nd numbers differ - expected: '3', found: '4'