为什么会RE啊
查看原帖
为什么会RE啊
877860
Just_Love_You楼主2024/4/11 21:05
#include<bits/stdc++.h>
#define endl '\n'
#define int signed long long
#define double long double
using namespace std;
constexpr int N=1e3+10;
constexpr int M=3e3+10;
constexpr int mod=998244353;
constexpr double esp=1e-9;
const double PI=acos(-1);
void solve()
{
    string s;
    cin >> s;
    int n;
    cin >> n;
    string str[n];
    for(int i=0;i<n;i++)
    {
        cin >> str[i];
    }
    int len=s.size();
    s+="    ";
    vector<int> nxt(len,-1);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=len-str[i].size();j++)
        {
            if(str[i]==s.substr(j,str[i].size()))
            {
                if(nxt[j]==-1)
                {
                    nxt[j]=i;
                }else
                {
                    if(str[nxt[j]].size()<str[i].size())
                    {
                        nxt[j]=i;
                    }
                }
            }
        }
    }
    vector<pair<int,int>> ans;
    for(int i=0,j=0;i<len&&j<len;i++)
    {
        int tmp=0;
        int cnt,res;
        int l=i;
        while(l<len&&l<=j)
        {
            if(nxt[l]^-1)
            {
                if(l+str[nxt[l]].size()>tmp)
                {
                    tmp=l+str[nxt[l]].size();
                    res=nxt[l]+1;
                    cnt=l+1;
                }
            }
            l++;
        }
        if(!tmp)
        {
            cout << -1 << endl;
            return;
        }
        j=tmp;
        ans.push_back({res,cnt});
    }
    cout << ans.size() << endl;
    for(auto [v,w]:ans)
    {
        cout << v << " " << w << endl;
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int o;
    cin >> o;
    while(o--)
    solve();

    return 0;
}
//
//⠀⠀⠀             ⠀⢸⣿⣿⣿⠀⣼⣿⣿⣦⡀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀ ⠀⢸⣿⣿⡟⢰⣿⣿⣿⠟⠁
//⠀⠀⠀⠀⠀⠀⠀⢰⣿⠿⢿⣦⣀⠀⠘⠛⠛⠃⠸⠿⠟⣫⣴⣶⣾⡆
//⠀⠀⠀⠀⠀⠀⠀⠸⣿⡀⠀⠉⢿⣦⡀⠀⠀⠀⠀⠀⠀ ⠛⠿⠿⣿⠃
//⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣦⠀⠀⠹⣿⣶⡾⠛⠛⢷⣦⣄⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣧⠀⠀⠈⠉⣀⡀⠀ ⠀⠙⢿⡇
//⠀⠀⠀⠀⠀⠀⢀⣠⣴⡿⠟⠋⠀⠀⢠⣾⠟⠃⠀⠀⠀⢸⣿⡆
//⠀⠀⠀⢀⣠⣶⡿⠛⠉⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⢸⣿⠇
//⢀⣠⣾⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⢀⣼⣧⣀⠀⠀⠀⢀⣼⠇
//⠈⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⡿⠋⠙⠛⠛⠛⠛⠛⠁
//⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⡿⠋⠀
//⠀⠀⠀⠀⠀⠀⠀⠀⢾⠿⠋⠀
//

2024/4/11 21:05
加载中...