yicongli

HIHO1441

Mar 6th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define gc c=getchar()
  6. #define r(x) read(x)
  7. #define ll long long
  8.  
  9. template<typename T>
  10. inline void read(T&x){
  11.     x=0;T k=1;char gc;
  12.     while(!isdigit(c)){if(c=='-')k=-1;gc;}
  13.     while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
  14. }
  15.  
  16. map<long long,string>shortest,longest;
  17. map<string,long long>state;
  18.  
  19. string s;
  20.  
  21. int main(){
  22.     int n,q;
  23.     cin>>s>>q;
  24.     n=s.length();
  25.     for(int i=0;i<n;++i){
  26.         for(int j=1;j<=n-i;++j){
  27.             string x=s.substr(i,j);
  28.             long long st=0;
  29.             for(int k=0;k<=n-j;++k){
  30.                 if(x==s.substr(k,j)){
  31.                     st|=(1ll<<(k+j-1));
  32.                 }
  33.             }
  34.             if(shortest[st]==""||j<shortest[st].length()){
  35.                 shortest[st]=x;
  36.             }
  37.             if(j>longest[st].length()){
  38.                 longest[st]=x;
  39.             }
  40.             state[x]=st;
  41.         }
  42.     }
  43.     while(q--){
  44.         cin>>s;
  45.         long long st=state[s];
  46.         cout<<shortest[st]<<" "<<longest[st];
  47.         for(int i=0;i<n;++i){
  48.             if(st>>i&1){
  49.                 cout<<" "<<i+1;
  50.             }
  51.         }
  52.         puts("");
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment