QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645498 | #6228. 字符串 | Cleshm | 100 ✓ | 337ms | 8928kb | C++14 | 1.4kb | 2024-10-16 18:44:23 | 2024-10-16 18:44:23 |
Judging History
answer
//by wxw
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,k;
string a,b;
int base[300010],hsh[300010];
int get_hsh(int l,int r)
{
return (hsh[r]-1ll*hsh[l-1]*base[r-l+1]%mod+mod)%mod;
}
int get_lcp(int x,int y)
{
int el=1,er=k,ans=0;
while(el<=er)
{
int mid=el+er>>1;
if(get_hsh(x,x+mid-1)==get_hsh(y,y+mid-1)) ans=mid,el=mid+1;
else er=mid-1;
}
return ans;
}
long long dfs(int now,vector<int> veca,vector<int> vecb)
{
if(veca.empty() || vecb.empty()) return 0;
vector<int> gta[26],gtb[26];
int lcp=k,lstwz=0;
for(int i:veca)
{
if(lstwz!=0) lcp=min(lcp,get_lcp(lstwz,i));
lstwz=i;
}
for(int i:vecb) lcp=min(lcp,get_lcp(lstwz,i+n)),lstwz=i+n;
if(lcp==k) return 1ll*k*min(veca.size(),vecb.size());
for(int i:veca) gta[a[i+lcp]-'a'].push_back(i);
for(int i:vecb) gtb[b[i+lcp]-'a'].push_back(i);
long long ans=0; int cnta=0,cntb=0;
for(int i=0; i<26; ++i)
{
ans+=dfs(lcp+1,gta[i],gtb[i]);
int in=min(gta[i].size(),gtb[i].size());
cnta+=gta[i].size()-in,cntb+=gtb[i].size()-in;
}
return ans+1ll*lcp*min(cnta,cntb);
}
int main()
{
base[0]=1; for(int i=1; i<=3e5; ++i) base[i]=base[i-1]*131ll%mod;
cin>>n>>k>>a>>b; a=' '+a,b=' '+b;
for(int i=1; i<=2*n; ++i) hsh[i]=(hsh[i-1]*131ll+(i<=n?a[i]:b[i-n]))%mod;
vector<int> veca,vecb;
for(int i=1; i<=n-k+1; ++i) veca.push_back(i),vecb.push_back(i);
cout<<1ll*k*(n-k+1)-dfs(0,veca,vecb);
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 2ms
memory: 4840kb
input:
11 1 rbbzzmxmbmz rbzmrbzxxxz
output:
3
result:
ok single line: '3'
Test #2:
score: 10
Accepted
time: 2ms
memory: 4688kb
input:
11 5 iiecieccice ecccceicicc
output:
27
result:
ok single line: '27'
Test #3:
score: 10
Accepted
time: 2ms
memory: 4784kb
input:
11 2 vfxaikwshqw vcrstlhgupu
output:
17
result:
ok single line: '17'
Test #4:
score: 10
Accepted
time: 2ms
memory: 4788kb
input:
11 5 abbaaaababb babbabbabba
output:
24
result:
ok single line: '24'
Subtask #2:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 2ms
memory: 4768kb
input:
189 183 ggzkilwnazromarxgofvbpvoiyxjezsnazromsuadvbqcrbpcgopuaflzxarxsclfzjymwofsoupxgrokklvydfclzkvzosyromseacgopuadvbqcadvbzgrovetzatvbgrgcrdfgwlyokkavyrooibhplfopwyrvkdqtplqjvetarxscoalmscxmjpzt pceqoxxlwnazromseacqiyzsbmksznaafomibhgsomseaccjgfsoupxgrokkavyromseavzzxarmprlpcgopuadvbqcrxhotzatvgt...
output:
1281
result:
ok single line: '1281'
Test #6:
score: 10
Accepted
time: 2ms
memory: 4624kb
input:
200 57 fepkbvxoerpcvroebkmqhnffauhmrupetettegzclvsuahdpjpbudmlgqoejupzgxwudnyuiyyjgmqhgwsgsgxwpkpqjszlxyoxueypcughhvttnxzskldvfngvvbzxsetkypupmwszsexkplmgspfbzxsetkypcughgwsgstdmjpgxlfzexlxygayahepkbkmqhnkkm oexzskldvfnudxwudnmxsetkvxoerxonxzjdoejuplcvroerphpzojpqjsjlrmqjueykphydhbkszlxykmdvfyyjgwsf...
output:
7863
result:
ok single line: '7863'
Subtask #3:
score: 10
Accepted
Test #7:
score: 10
Accepted
time: 2ms
memory: 4752kb
input:
200 186 bmtexhhnkxtturdmbdwlnojqbrgmfsldftmxfuhwcsfvhqrwtyxahyaeqhdmptdzatiusqlzplnpwwpjtqruzwzfxrkmolppethnfcjahkggzrahuhjxtzzxftapeckzluzbawtqebmkuqvowxjjejyhlwviatpwsgrjlskzdemcjaikeqodtkzjfpuxjvajbecvzbfr iuaztcsejcanhhcxbceaivostovczsbsrqongikbzzrgrmubfqexqczjgzhdonhidpecjyugbbgsalfmosipjpumrgk...
output:
2783
result:
ok single line: '2783'
Test #8:
score: 10
Accepted
time: 2ms
memory: 4796kb
input:
200 91 babbaabaaabaabbababaaaaabababbaabbabababbabbabbaabbabbbabbaaabbbbbaaaabbbbbabbbbbbabaabbabbbbbbbabbabababbbbbbbaabbbbbabbaababbbaaababaaababbabbaaabbbbbaaaaaabababaaababbbababababbbabbbababbbababaabaa aabaabbaaaabbaaabbbbbbbbaabbbaaabbaabbabbababbabbbbbbbababbbabbababbbaaaababbbbbbbbbabaaabab...
output:
9267
result:
ok single line: '9267'
Test #9:
score: 10
Accepted
time: 2ms
memory: 4792kb
input:
200 150 nbosezhgtlbulcqhzxmsekhmlwjxdnykhhrppccxytopamjpnmmlwjnvzxmlmzbgonxrfjnbehezhgtlbulgvjewofqnuurfjngckhhreqocuonxrlpthohchzzuatphchzwumrbokiqfbsbehnxsekhcbyoighozeesdxrbgonxrthozeebclvtpptlyjfgicbgbiko fvzctlpthoqfbssekhcbyoikzeexsezhgtlbulchhrebswwfgjjqxdnmtpotlpwcxytopauafopamjpnmzxmlmzbgon...
output:
7551
result:
ok single line: '7551'
Subtask #4:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 4ms
memory: 5756kb
input:
1970 76 dbajnykavlpizxpttpyxdtospawwemltpdearvnatpwekllfrwdelahxyilixhccmsukvusqodalaqqrxnyufonqzubxmddmryuysetyxlqrrepcajjhtoriwliaubkocbkyfwvdsuchvtxnhytznlmkzggxmolwkrwqjyhvnipugloyrpnplaokjtlwijwbdzttpeqjqdfqgtnlmkzggxmolwkccgorxwpipugloyrpnplaoubxmdoslibzcwbgqygqjmhpfbiggjanvjamjbwkcpzoucifnkjo...
output:
99038
result:
ok single line: '99038'
Test #11:
score: 10
Accepted
time: 2ms
memory: 5692kb
input:
2000 1800 vagekztgqyfqacujtmjjdggeisvtokooiolvurvumezuhipwklzgpivjrtfscnnsmbaumbnvwfrafjhrsotdfuhkafprhzrtjhjqmgduylebgxjqgmwtqocgthlxcjbxjhhpwaagzdpwmvagekztgqyfqacujtmjjdggeisvtokooiolvurvumezuhipwklzgpivjrtfscnnsmbaubvnmmftofygcvjsnotectmvyyagrpdgtcnwduojcrzwdsvqutkizcedhuqupwlrnlerheesueheorqfrf...
output:
359745
result:
ok single line: '359745'
Subtask #5:
score: 10
Accepted
Test #12:
score: 10
Accepted
time: 0ms
memory: 4832kb
input:
2000 110 cctdrvumnyzeieuzynrhpgdjhtblkwegiqspeqdvlfquembvbgkbxbxqxkzcrejmjybxpaajjbahvnllhsnwqhwbodppwugaglhiccqgwfrqwrrtzvarjphzdvpanlilvvubyzfpinkncmusfpeythsyaqehcpsqeoarrjesmszoxjdwokscxiopdvlrrcatthspslqeteanbgvonavsekcjlxzqkdknewqwkzlrkogaqarlookpwmdbglitjpljgkskomjlpjaxnqneorxlvaacsepppualnwg...
output:
204737
result:
ok single line: '204737'
Test #13:
score: 10
Accepted
time: 3ms
memory: 4684kb
input:
2000 1568 bbaaabbbbbabbbbbbbbabaabbbbaaabbbaaaabbbabbbbbbaabababbaabbabaabbabbabbbbbbbbbaabbaaaaaaaaaaaaababbabbbbababaaaaaaaabbababaaababaaaaaaabbbbaaaababbabbaaabaaaaabbbaabbbbabbabbbaabbbbabbababbababaaabbbaaaabbaaabbabbaaaabbbbabbbbaaabbbababbbaaabbaabaaaaabbaabbabbabaaabbaaaaabbbabaaaaababaabbb...
output:
675034
result:
ok single line: '675034'
Test #14:
score: 10
Accepted
time: 3ms
memory: 4772kb
input:
2000 1344 lolkxicffjoahkfdggddidecuqrfpfooutddnzbcazpcocgubmrigntptbyvztzqgicupxqkjakctdgmbqtfljxesdkumgzypjteiomnavydabegdsueyupxucuopzhucgrbipveldsgvdzxbtskfoficlremrcxzgnhkumgkqhkgrvdabegdsueyutemrcxzgnhkbkqhylgoldsvtgbljrmcbicgqshbetgofdjcxzlysumcfxpcovccfclgjltgmjvwlgghxzvwlgghxzhanmfwhlhxsvrno...
output:
880113
result:
ok single line: '880113'
Subtask #6:
score: 10
Accepted
Test #15:
score: 10
Accepted
time: 7ms
memory: 5992kb
input:
136531 132287 dqkgbnnyzwmbzckupyuuupmenzjfpooutxplglbcqcyeyniuzhgecanatlvlfowlzqjrztednqbhopdrxaaephxnbfaqqfoqovicxazopnkttwzqvlyqrgistvpetfmhhughbqrncmrdbgmyfmivuxbwtuqbrqazuyygcxxgcragzwwxoxqyvpzugywirksslmhsspzountdivthtkvvdqhuoncsdrcewhqkptcwfuysrhqkgrivpckevgbejvwryjtsglmditbbjtxqubwruuqngjugbu...
output:
561550095
result:
ok single line: '561550095'
Test #16:
score: 10
Accepted
time: 33ms
memory: 7088kb
input:
150000 121497 zngvmoixlvkgnadwokornampshpamkzttdsrlrdpljvnyhtumgbjrszxmlbjvuqqilfbwzozrbrofqdiwivrtylbupfvinlggpqojtpqnyjmyisydgzwcpicsacutzkpcttcktknqmvhjvvwkomytrhajtifdqldcfnhhwaavxfqtazukudojiyhxpxqoasmlvfbgavfdamyvdapmlxjvxrzvldbthtagauvczpuofglawxdlhvfughisxfxhskuuybyipbwxauxuytsagjronxoimcbzd...
output:
3463078308
result:
ok single line: '3463078308'
Subtask #7:
score: 10
Accepted
Test #17:
score: 10
Accepted
time: 82ms
memory: 7656kb
input:
93376 10006 qvajyijbvmbtcgejthwkwatplbtmscyqqlbjmooteoyzbushasbdruqbwsvdjwzwnfzkawoaqwwibibmsnmnbinktjybibswordjyxipmonbqujxmexlgnchbiqsalrrlnupdhaxvaehcnbjsmcypcakmmengrpogkisfrqghzuakdwdyipuioibvatllelgtqaeqnnmcqcooftbyvjbrfyczwmbiuccckfgdjkdhfdnygsmpspulqwlaorrepzauxbmwpyfqzkkgjyenyfqpulqkhbuegic...
output:
833972344
result:
ok single line: '833972344'
Test #18:
score: 10
Accepted
time: 140ms
memory: 7972kb
input:
100000 3453 klyarstaybbaawhfordfxixwdlbxplhsequnbxtfmeanqfqimnkbcyqqyedrdtpstcddekspidolwgrqelojswgdfnaepcurhsyhvtdwfgufebqjrcyizbinzlntltteasxpwybvkiowzrdfwqybqglvtakkkejwiuvgypdtjycxiqrjfpwitfkrqkifjmxwzfpqgvvhdjfcfufqzxsnslakggtbtbzgrakleovglwbwhayczuygizjvsncrchniozxywswpchtohckqulsvytglehfhgtmk...
output:
246347135
result:
ok single line: '246347135'
Subtask #8:
score: 10
Accepted
Test #19:
score: 10
Accepted
time: 37ms
memory: 6600kb
input:
90081 61832 lqqwzyiwccivztgzvdcjowmgtohjstttigxkkciexmyicxputfgudxdwemcpnnforfltonoeevwxptmbzvelckmgmboebsmfqgvxwhgdlwezreycawmjgnlinxzjsbaqjafsrwhngmorjjubzbwynwgblayrduekrmrenvcuqdmnebsjqvhgcugnwppxtbuuekizxwcpvsusxmzmhzdsmlurhzugnitxtplmsefrsihjdvroaihlluqtttthcyyuekitefhcjcrwrcricypqhehanczcqarp...
output:
1742191016
result:
ok single line: '1742191016'
Test #20:
score: 10
Accepted
time: 337ms
memory: 8928kb
input:
100000 18330 aabbbaaaabbaabbaababababaaabbabaabbaaaabaabbbbbbababbbababaabaabbbaabbbbbbaaabbabbabbabbbbbaaabaaabbbbbabbabbabbabbaaabbaaababbaaabbaaabababbaabaabbbabaababbaabaabbbbabbabaaaabbbabbbaabbbbbaaaaabbaabbbaaaaabbaaaaaabaaabbbbabbaabbaabaaaababaaaabbbabbbaaabbbabaaaabaaababbbabaabaabaabbabbb...
output:
1438031519
result:
ok single line: '1438031519'
Subtask #9:
score: 10
Accepted
Test #21:
score: 10
Accepted
time: 92ms
memory: 7896kb
input:
148067 68475 ndqltwlfnbfgjjrxfzwzlxjwuytfnmgkoozbgxmjhagcxowjeowjshohauryuvbhyijzktzzjnffhccmufbutucqpymbncwdopfziqpdcxqnkgwqekmyfxfftyzmwuyutgddadhmtteqefmbwpuauvsffbcqjhjwukvpleaykjajfdxhcspygwkikuwmtnjhjgxoaktshigoysxhrjjlptordbzoumukatnlzygzcykbnxgvlevngkwygjqrpyaodfutjhyyfygjccqkyjnzebcujwvvokd...
output:
5449905181
result:
ok single line: '5449905181'
Test #22:
score: 10
Accepted
time: 33ms
memory: 6492kb
input:
150000 125148 ccpbdfncvudrbqqhkphhmpqgzdnpfztoddoznzptiocplmqasljuuplejyjyczoencfvaxxkwwdradqpgrxhcenakmttyisfuzksmtuhfryqrzqjbmfgoiaxnpgvkiaidndioksdtfhojgfxxnceywvkkbtdresxebwpiqqxqcwgemgjblwugmolkozcqvueobmapsrdxwllpesqiberzefaktdnxxydxorremnsjsesvvgnwugwmzkgdeathtnvqxqzkzmhnihtopfmbvaaeunnzzuiix...
output:
3100212388
result:
ok single line: '3100212388'
Subtask #10:
score: 10
Accepted
Test #23:
score: 10
Accepted
time: 11ms
memory: 6192kb
input:
142928 139024 jdgusjdfvxvfdtvgwwumkrnhgpckfgeoagwnspjyiexkkgudqtkxbeprmpvzfsdtoexmccgqmgewithttrtoceddynvnvhurikgwhvdibmyaokzysmyrjxbwymdyskhsdhnhhbhoeyzsepiyvebfyojfxzlhrxozvsvzdmlggrtbyemqcxixqnmzscepaoogdxfdrvbwxxscokuucdycppvssnckvazqoutebossriaxuhnesksxzycabccoafbluystrytufwxhhdrcfumanheulnbgph...
output:
542881204
result:
ok single line: '542881204'
Test #24:
score: 10
Accepted
time: 218ms
memory: 7956kb
input:
150000 101453 bbbaaabbbabbbaababaabaaaababbbbbaabaaabbababbababbaaaababbbbbaababbbabbbabaaaabaabaaaabbbbabbababbabbbaababbababaabbaababbbbbbaaaaaaabbbbaaabbababbbbbbbbbbbbabbbaaaaabaaaaabbaaabaabbbbbaabbbaabbabbaaaababaabbbaaaabbbaababaabbbaaaabaabbbabbabbaaababababbaaabaabbbabbbbbababbbbbbbbbbbaabb...
output:
4870040636
result:
ok single line: '4870040636'