本题是要求你找出一个组内比原字符串权值大的前缀,而一个组内包含了其他字符串的前缀,但可能也适配于这个字符串。所以说要记录这些前缀的个数才能解出这个问题。
一个方法是用std::map这样的一个红黑树字典,可以直接把string类型的前缀出现次数用int/ll类型的数字统计下来。然后再计算各前缀的权值与个数之积,逐一与原字符串权值进行比对,即可得到答案。
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf_s("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 33;
inline ll lldcin()
{
ll tmp = 0, si = 1;
char c;
c = getchar();
while (c > '9' || c < '0')
{
if (c == '-')
si = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
tmp = tmp * 10 + c - '0';
c = getchar();
}
return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
string strs[500000];
ll identify[40],ans[500000];
ll cost[500000];
map<string,ll>prefix;//记录前缀出现次数
int DETERMINATION()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
ll n,m;
cin>>n>>m;
for(int i=1;i<=26;i++)
ci