QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750915 | #9747. 字符串复制 | _LSA_ | WA | 424ms | 54628kb | C++14 | 2.3kb | 2024-11-15 16:19:38 | 2024-11-15 16:19:38 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
ll X = 0 ,r = 1;
char ch = getchar();
while(!isdigit(ch) && ch != '-') ch = getchar();
if(ch == '-') r = -1,ch = getchar();
while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
return X*r;
}
const int N = 1e6+10;
const int mod = 998244353;
struct SA{
int n;
string ch;
int sa[N],rk[N],height[N],x[N],y[N],cnt[N];
void getsa(){
int m = 127;
for(int i=1;i<=n;i++) cnt[x[i] = ch[i]]++;
for(int i=1;i<=m;i++) cnt[i] += cnt[i-1];
for(int i=n;i>=1;i--) sa[cnt[x[i]]--] = i;
for(int k=1;k<=n;k*=2){
int p = 0;
for(int i=n-k+1;i<=n;i++) y[++p] = i;
for(int i=1;i<=n;i++) if(sa[i] > k) y[++p] = sa[i]-k;
for(int i=1;i<=m;i++) cnt[i] = 0;
for(int i=1;i<=n;i++) cnt[x[i]]++;
for(int i=2;i<=m;i++) cnt[i] += cnt[i-1];
for(int i=n;i>=1;i--) sa[cnt[x[y[i]]]--] = y[i];
swap(x,y); p = 1;
x[sa[1]] = 1;
for(int i=2;i<=n;i++)
x[sa[i]] = y[sa[i]] == y[sa[i-1]] && y[sa[i]+k] == y[sa[i-1]+k] ? p : ++p;
m = p;
if(m >= n) break;
}
}
void getheight(){
for(int i=1;i<=n;i++) rk[sa[i]] = i;
int k = 0;
for(int i=1;i<=n;i++){
if(rk[i] == 1) continue;
if(k) k--;
int j = sa[rk[i]-1];
while(ch[i+k] == ch[j+k]) k++;
height[rk[i]] = k;
}
}
void init(string s){
n = s.size();
ch = " "+s;
getsa(); getheight();
}
ll getcnt(){
ll res = 1ll*n*(n-1)/2+n;
for(int i=2;i<=n;i++) res -= height[i];
return res;
}
}S2,S3;
int n;
ll ans,m;
int main(){
n = read(); m = read();
string s; cin >> s;
if(m == 1){S2.init(s); cout << S2.getcnt(); return 0;}
string s2 = s+s,s3 = s+s+s;
S2.init(s2); S3.init(s3);
ll cnt2 = S2.getcnt(),cnt3 = S3.getcnt();
ans = (cnt2+(cnt3-cnt2)%mod*(m-2)%mod)%mod;
cout << ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 34324kb
input:
6 2 mantle
output:
57
result:
ok single line: '57'
Test #2:
score: 0
Accepted
time: 7ms
memory: 32472kb
input:
12 1919810 ifamjlifamjl
output:
138226305
result:
ok single line: '138226305'
Test #3:
score: 0
Accepted
time: 0ms
memory: 32272kb
input:
13 935330878 aabbbbababbaa
output:
348310505
result:
ok single line: '348310505'
Test #4:
score: 0
Accepted
time: 412ms
memory: 53100kb
input:
300000 1000000000 rqwcfnskpxmdplyemxtntenuvjcbtggljuravmoaipbujlseqtuakblnqzbirxowfaeykxwldpeovyuuvjvskbllmtdlsfswoklvdpuuujryuvzbabieklgkcbqdocbmmwsjlfiqxvwocsexuldtiaucurmiewfrggbnbfmxqtaabxnbzcjnavvuuvowvyazzmgtdwvjlmwxpxontrusqgipfvfsjtckxdrloofzmjxxhlexhqcjchgryycbybcnmbjsaffaeaitkalawjuporbnzo...
output:
478922465
result:
ok single line: '478922465'
Test #5:
score: 0
Accepted
time: 15ms
memory: 34400kb
input:
3000 546279171 ddcaddabbadcdbcbacaddcabcbdcadbdadabdbadbbbbbbbcbddddbbbcdddcabcabbacadcbddbcddaabcacbcdcbccccbddababbbcacacdcaddaadacbcabbcccdbbabbddcdccabccaabbbdbaacccddccbbdbadacdcaaabbddccdbacddddaacaacbadcdacdcaddcdbcbdcbccaabadabcdcdaddaadcdadbaabacddacbcbbdaacdaccdadcdcabaacabcbdcacdacbcccdad...
output:
375109583
result:
ok single line: '375109583'
Test #6:
score: 0
Accepted
time: 20ms
memory: 32620kb
input:
20000 713238600 ddaceddaaaaaebbaccedaaaacdedadceecbcedaeabcaaecbdaebebdbdebebdddbdbabadabdddaaacdbccbccecdeaebcdabcacdbedacadcccecaddcaeeecbbabcbbccebceacdeeadbbcdcceaebaecaccbbabbceedbcedbbbbbbdeaadaaeaaecabeddbdeeaaeabcbaedbedeabbdecbacaabdadbabbdacabdcdaecaaaabecbdddeabadaacbddceecbeebcadacdbcedd...
output:
793179337
result:
ok single line: '793179337'
Test #7:
score: 0
Accepted
time: 249ms
memory: 50924kb
input:
200000 432588167 gfeaccabbeccbfbcafcdfebabeebfgdccbgbcbddcfacccedebcagdccagafefdcbdgfcbadaeffcdaebbdadgfgdefdgbgaeeadfcebbeaaegbbcbfdeegdcfdgebddadaceaacggcgaecddfdcgbgeaffgbgfcacdddcbgaddecceaefcbddebgceeegbceceegcaaadgccdbcffebaaeddcdgbgagbbcfffaabafcagfaabfadcbadggbdcfebgbagggagdfbccdbeafgcbegfcf...
output:
68059895
result:
ok single line: '68059895'
Test #8:
score: 0
Accepted
time: 373ms
memory: 54628kb
input:
300000 4405849 bbbabbbbaabaabaabbbaabbaaaabaaabbabbbbabbbbbabbbbababaaabbaaababbbaaabbbabbbbbaababbaabaaabbabbaaaaaabbabaaabbbbaabaabbbaaabaaaababbabbbbabbbbaaaaaaabababaaabababaabababaaaabbababbbbaabbbaabbabaabaabaaabbababbaababbaaabaaabbbababbabaababbabbabbabaabbbbbababbabaabbbaabaabbaabaababababb...
output:
147294182
result:
ok single line: '147294182'
Test #9:
score: 0
Accepted
time: 424ms
memory: 53480kb
input:
300000 59262767 tvjfbbccnjyudccwhwkvmfqvuoxqqktkbiqqtwfdwgxcqiljnsbyelzztivlpuylpcpupeccakwmhfjtlayinlvzptznmyqgtgsfrbojfsdwpqlxyhcvhyvioaeccqqbtjbvynwprudzgbtyknbugnbhcbmwkmsfokfmbnyxmidzshdsxibmhetswuyumbiedddkibvilqlgunananvbsiukuwewuibczodpdarorttepvewabnxslnpreoitjikgfyurecxqulvbzyzqagprzybrwln...
output:
638033683
result:
ok single line: '638033683'
Test #10:
score: 0
Accepted
time: 420ms
memory: 54080kb
input:
298942 948827395 eahqgctdomejjtldhbimwmmevmapsbmtvsrvlhhftqqnmddwgsskutelqwedplacbrkesadimqlcdqsbpqdcfotdpfwjhcdsqolungoeiwnqfbrwutdcsacmicqqlgvusplnmsqcxrxhsrpuetsmcohpntbicqpxqokpndjbkraicfmthbbxfkmcvksbmxplbcalkcskixaswxrewthtmdjhrwjdbtpqvenicfklibxnfnuwpternjevhiixjvhgvscowwjwvjocpkhbnrqxcuxvjoh...
output:
861490076
result:
ok single line: '861490076'
Test #11:
score: 0
Accepted
time: 0ms
memory: 34296kb
input:
1 114514 a
output:
114514
result:
ok single line: '114514'
Test #12:
score: 0
Accepted
time: 0ms
memory: 17896kb
input:
1 1 a
output:
1
result:
ok single line: '1'
Test #13:
score: -100
Wrong Answer
time: 27ms
memory: 24816kb
input:
300000 1 bceuzejmvekodaqwzluhbnyzmkedzgrzkovzvggdwzqhnjltgiezlmbzdsmhpsnvotnvwbfrstzwpmtjyewecgeevcoyeszmamvvgvwtswrpgtakoomlgmwitprmmjfeftqlrlqitcupxxugnzzihepbewitjiqinxplqehcbuyrevryzgpszslrxjcevrhrivzerjzbonqltluholuiubnpwncrkkiivtjflvkinretburctccdicprnbhrkkbgkzaidnskdizklipgnxxwuhesebzoohjcmqq...
output:
44999184206
result:
wrong answer 1st lines differ - expected: '78188321', found: '44999184206'