昵称检索(杭电暑期2024)

 

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

void solve();

const int N = 1e6 + 10;
int days[]={0,31,29,31,30,31,30,31,31,30,31,30,31};

signed main() {
    IOS;
    ll t;
    cin >> t;
    while(t--)
        solve();
    return 0;
}

ll ctoll(char a,char b)
{
    return (a-'0')*10+b-'0';
}

void solve() {
    ll n,m;
    string s,t;
    cin >> n >> m >> s;
    vector<string> name;
    for(int i = 1; i <= n; ++i)
    {
        cin >> t; name.pb(t);
    }
    map<char,vector<ll>> pos_char,pos_int;
    vector<ll> dp(m+1,0);
    for(int i = 0; i < m; ++ i)
    {
        if(s[i] >= 'a' && s[i] <= 'z') pos_char[s[i]].ps(i);
        else pos_int[s[i]].ps(i);
    }
    for(char d2 = '0'; d2 <= '9';  ++ d2)
    {
        if(pos_int[d2].empty()) continue;//没有这个数字
        ll pos_d2 = pos_int[d2].back();//选取最后一个
        for(char d1 = '0'; d1 <= '3'; ++ d1)
        {
            ll day = ctoll(d1,d2);
            if(day<1 || day>31) continue;//不可能的日期
            if(pos_int[d1].empty()) continue;//没有
            auto to_pos = lower_bound(all(pos_int[d1]),pos_d2);//寻找小于的最后一个
            if(to_pos == pos_int[d1].begin()) continue;
            ll pos_d1 = *(--to_pos);
//            cout << "day:" << day << endl;
            for(char m2 = '0'; m2 <= '9'; ++ m2)
            {
                if(pos_int[m2].empty()) continue;//没有
                to_pos = lower_bound(all(pos_int[m2]),pos_d1);
                if(to_pos == pos_int[m2].begin()) continue;//没有前面的满足条件的数字
                ll pos_m2 = *(--to_pos);
                for(char m1 = '0'; m1 <= '1'; ++ m1)
                {
                    ll month = ctoll(m1,m2);
                    if(month<1 || month>12) continue;//不满足的月份
                    if(days[month] < day) continue;//月与日不匹配
                    if(pos_int[m1].empty()) continue;//没有
                    to_pos = lower_bound(all(pos_int[m1]),pos_m2);
                    if(to_pos == pos_int[m1].begin()) continue;
                    ll pos_m1 = *(--to_pos);
                    dp[pos_m1]++;
//                    cout << "sb:" << month << day << endl;
                }
            }
        }
    }
    ll ans = 0;
    for(int i = m-1; i >= 0; -- i) dp[i] += dp[i+1];
    for(int i = 0; i < name.size(); ++ i)
    {
        ll ix = -1;//第一个匹配的下标
        ll f = 1;
        for(int j = 0; j < name[i].size(); ++j)
        {
            auto c = name[i][j];
            auto it = upper_bound(all(pos_char[c]),ix);
            if(it == pos_char[c].end())
            {f = 0;break;}//匹配不了了
            ix = *it;
        }
       if(f) ans += dp[ix];
    }
    cout << ans << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值