Submission #1042038

# Submission time Handle Problem Language Result Execution time Memory
1042038 2024-08-02T13:04:37 Z PM1 Dabbeh (INOI20_dabbeh) C++17
0 / 100
284 ms 55056 KB
#include <bits/stdc++.h>
using namespace std;
const int mxn=3e5+5;
int n,m,l,r,trie[mxn*2][26],cnt=0,sz[mxn*2],par[mxn*2];
string s[mxn],a;
vector<int>v;
void add(int d,int x,int i){
	if(d==s[i].size())
		return ;
	if(trie[x][s[i][d]-'a']==0){
		trie[x][s[i][d]-'a']=++cnt;
		par[cnt]=x;
	}
	sz[trie[x][s[i][d]-'a']]++;

	add(d+1,trie[x][s[i][d]-'a'],i);
}
void up(int x){
	while(x!=0){
		sz[x]++;
		x=par[x];
	}
}
void get(int x=0){
	//cout<<x<<" ";
	if(l==r+1 || trie[x][a[l]-'a']==0 || sz[trie[x][a[l]-'a']]==0 ){
		v.push_back(x);
		if(x==0)
			l=1e9;
		return;
	}
	sz[trie[x][a[l]-'a']]--;
	
	get(trie[x][a[l++]-'a']);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		add(0,0,i);
	}

	cin>>a;
	while(m--){
		cin>>l>>r;
		r--;
		int ans=0;
		while(l<r+1){
			get();
			ans++;
		}
		if(l==1e9)
			cout<<-1<<'\n';
		else
			cout<<ans<<'\n';
		while(v.size()){
			up(v.back());
			v.pop_back();
		}
	}
}

Compilation message

Main.cpp: In function 'void add(int, int, int)':
Main.cpp:8:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  if(d==s[i].size())
      |     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 120 ms 55056 KB Output is correct
3 Incorrect 284 ms 44048 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 30652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 120 ms 55056 KB Output is correct
3 Incorrect 284 ms 44048 KB Output isn't correct
4 Halted 0 ms 0 KB -