WA on #9
查看原帖
WA on #9
835600
Big_Dinosaur楼主2024/7/21 21:29
#include<bits/stdc++.h>
#define int long long
#define ri register int
using namespace std;
namespace IO{
  inline int r(){
    int z=1,y=0;char t=getchar();while(t<'0'||t>'9'){if(t=='-')z=-1;t=getchar();}
    while(t<='9'&&t>='0'){y=(y<<1)+(y<<3)+(t^48);t=getchar();}return z*y;
  }
  inline void w_(int x){if(x<0){x=-x;putchar('-');}if(x==0)return;w_(x/10);putchar(x%10+48);}
  inline void wln(int x){if(x==0)putchar('0');else w_(x);putchar('\n');}
  inline void ww(int x){if(x==0)putchar('0');else w_(x);putchar(' ');}
  inline void w(int x){if(x==0)putchar('0');else w_(x);}
}
using namespace IO;
namespace D1n0{
  int n,charnum[26]={1,1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6,7,7,7,8,8,8,9,9,9},ch[101];
  string s,words[101],word[101];
  inline string to_num(string words){
    string Ans;
    for(ri i=0;i<words.size();++i)Ans+=char(charnum[words[i]-'a']+'0');
    return Ans;
  }
  inline int same(int x,int y){
    if(s.size()-x<words[y].size())return 0;
    for(ri i=0;i<words[y].size();++i)if(words[y][i]!=s[i+x])return 0;
    return 1;
  }
  inline void _(){
  n=r();
  cin>>s;
  for(ri i=1;i<=n;++i){
    cin>>word[i];
    words[i]=to_num(word[i]);
  }
  for(ri i=0;i<s.size();++i)
    if(i!=0&&ch[i]==0)continue;
    else{
      for(ri j=1;j<=n;++j)if(same(i,j))ch[i+words[j].size()]=j;
    }
  stack<string>st;
  string Ans;
  for(ri i=s.size();i;i-=word[ch[i]].size()){
    st.push(word[ch[i]]);
    if(word[ch[i]].size()==0){
      printf("No Solutions!");return;
    }
  }
  while(!st.empty()){
  cout<<st.top();st.pop();
  if(!st.empty())putchar(32);
  }
  }
}
signed main(){D1n0::_();}
2024/7/21 21:29
加载中...