题目链接:TUOJ
#include<bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
#define N 300010
const int mod = 929;
int w, s;
int mo = 0, k;
int cnt = 0;
bool f = 0;
char t[3] = {'A', 'a', '0'};
int d[10000], g[10000][2];
int check(char t)
{
if (t >= 'A' && t <= 'Z')return 0;
if (t >= 'a' && t <= 'z')return 1;
if (t >= '0' && t <= '9')return 2;
return 2;
}
void doo(int k)
{
if (f == 0)
{
d[cnt] = k;
f = 1;
}
else
{
d[cnt] *= 30;
d[cnt] += k;
cnt++;
f = 0;
}
}
void solve()
{
cin >> w >> s; //有效数据区每行能容纳的码字数和校验级别
string stri;
k = pow(2, s + 1);
if (s == -1)k = 0;
cin >> stri;
int len = stri.size();
cnt = 1;
for (int i = 0; i < len; i++)
{
int now_mo = check(stri[i]);
if (mo == 1 && now_mo == 0) //两次
{
doo(28);
doo(28);
mo = now_mo;
}
else if (mo != now_mo) //一次
{
int k = 28;
if (now_mo == 1)k = 27;
doo(k);
mo = now_mo;
}
//不换
doo(stri[i] - t[mo]);
}
if (f == 1)
{
doo(29);
}
while ((cnt + k) % w != 0)
{
doo(30);
doo(0);
}
int t = k;
while (t--)
{
doo(0);
doo(0);
}
d[0] = cnt - k;
cnt--;
for (int i = 0; i <= (cnt - 1) / 2; i++)
{
d[i] += d[cnt - i];
d[cnt - i] = d[i] - d[cnt - i];
d[i] = d[i] - d[cnt - i];
}
//
if (s == -1)
{
for (int i = cnt; i >= 0; i--)
{
cout << d[i] << endl;
}
return ;
}
//
//cout<<k<<endl;
int b = -3;
g[1][1] = 1;
g[0][1] = -3;
for (int i = 2; i <= k; i++)//0-k
{
b *= 3;
for (int j = 0; j <= i; j++)
{
g[j][0] = g[j][1] % mod;
g[j][1] = 0;
}
for (int j = 0; j < i; j++)
{
g[j + 1][1] += g[j][0];
}
for (int j = 0; j <= i; j++)
{
g[j][1] += g[j][0] * b % mod;
}
}
for (int i = cnt; i >= k; i--)
{
cout << d[i] << endl;
}
while (cnt >= k)
{
int bei = d[cnt] % mod;
if (bei == 0)
{
cnt--;
continue;
}
for (int j = k; j >= 0; j--)
{
d[cnt - k + j] -= bei * g[j][1] % mod;
d[cnt - k + j] %= mod;
}
cnt--;
}
for (int i = cnt; i >= 0; i--)
{
cout << ((mod - d[i]) % mod + mod) % mod << endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
{
solve();
}
return 0;
}