Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define gc c=getchar()
- #define r(x) read(x)
- #define ll long long
- template<typename T>
- inline void read(T&x){
- x=0;T k=1;char gc;
- while(!isdigit(c)){if(c=='-')k=-1;gc;}
- while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
- }
- map<long long,string>shortest,longest;
- map<string,long long>state;
- string s;
- int main(){
- int n,q;
- cin>>s>>q;
- n=s.length();
- for(int i=0;i<n;++i){
- for(int j=1;j<=n-i;++j){
- string x=s.substr(i,j);
- long long st=0;
- for(int k=0;k<=n-j;++k){
- if(x==s.substr(k,j)){
- st|=(1ll<<(k+j-1));
- }
- }
- if(shortest[st]==""||j<shortest[st].length()){
- shortest[st]=x;
- }
- if(j>longest[st].length()){
- longest[st]=x;
- }
- state[x]=st;
- }
- }
- while(q--){
- cin>>s;
- long long st=state[s];
- cout<<shortest[st]<<" "<<longest[st];
- for(int i=0;i<n;++i){
- if(st>>i&1){
- cout<<" "<<i+1;
- }
- }
- puts("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment