QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227191 | #6228. 字符串 | SorahISA | 50 | 192ms | 101136kb | C++20 | 3.2kb | 2023-10-27 01:15:42 | 2023-10-27 01:15:42 |
Judging History
answer
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA
const int maxc = 1'200'000; /// length <= 8
struct Trie {
struct Node {
array<int, 2> cnt;
vector<pair<int, char>> ch;
Node() : ch(0) { cnt[0] = cnt[1] = 0; }
int& operator [] (char c) {
for (int i = 0; i < SZ(ch); ++i) {
if (ch[i].second == c) return ch[i].first;
}
ch.emplace_back(-1, c);
return ch.back().first;
}
};
vector<Node> trie;
void init() {
trie.clear(), trie.shrink_to_fit();
trie.eb();
}
void insert(const string &S, int tp) {
int now = 0;
for (const char &c : S) {
if (int &tmp = trie[now][c]; tmp == -1) tmp = SZ(trie), trie.eb(), now = tmp;
else now = tmp;
}
++trie[now].cnt[tp];
}
int dp(int now, int hei) {
int64 ans = 0;
for (auto [ch, c] : trie[now].ch) {
if (ch != -1) {
ans += dp(ch, hei-1);
trie[now].cnt[0] += trie[ch].cnt[0];
trie[now].cnt[1] += trie[ch].cnt[1];
}
}
// debug(tmp, hei, trie[now].cnt[0], trie[now].cnt[1]);
int64 score = min(trie[now].cnt[0], trie[now].cnt[1]);
ans += score * hei;
trie[now].cnt[0] -= score, trie[now].cnt[1] -= score;
return ans;
}
};
void solve() {
int N, K; cin >> N >> K;
string S, T; cin >> S >> T;
Trie trie; trie.init();
for (int i = 0; i <= N-K; ++i) trie.insert(S.substr(i, min(K, maxc/N)), 0);
for (int i = 0; i <= N-K; ++i) trie.insert(T.substr(i, min(K, maxc/N)), 1);
cout << trie.dp(0, K) << "\n";
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
solve();
}
return 0;
}
#else
#include <bits/stdc++.h>
using namespace std;
// #define int int64_t
#define double __float80
using int64 = long long;
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "%s", "\u001b[33m"), \
fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), \
fprintf(stderr, "%s", "\u001b[0m")
template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
#endif
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3616kb
input:
11 1 rbbzzmxmbmz rbzmrbzxxxz
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
11 5 iiecieccice ecccceicicc
output:
27
result:
ok single line: '27'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
11 2 vfxaikwshqw vcrstlhgupu
output:
17
result:
ok single line: '17'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
11 5 abbaaaababb babbabbabba
output:
24
result:
ok single line: '24'
Subtask #2:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 0ms
memory: 3692kb
input:
189 183 ggzkilwnazromarxgofvbpvoiyxjezsnazromsuadvbqcrbpcgopuaflzxarxsclfzjymwofsoupxgrokklvydfclzkvzosyromseacgopuadvbqcadvbzgrovetzatvbgrgcrdfgwlyokkavyrooibhplfopwyrvkdqtplqjvetarxscoalmscxmjpzt pceqoxxlwnazromseacqiyzsbmksznaafomibhgsomseaccjgfsoupxgrokkavyromseavzzxarmprlpcgopuadvbqcrxhotzatvgt...
output:
1281
result:
ok single line: '1281'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4056kb
input:
200 57 fepkbvxoerpcvroebkmqhnffauhmrupetettegzclvsuahdpjpbudmlgqoejupzgxwudnyuiyyjgmqhgwsgsgxwpkpqjszlxyoxueypcughhvttnxzskldvfngvvbzxsetkypupmwszsexkplmgspfbzxsetkypcughgwsgstdmjpgxlfzexlxygayahepkbkmqhnkkm oexzskldvfnudxwudnmxsetkvxoerxonxzjdoejuplcvroerphpzojpqjsjlrmqjueykphydhbkszlxykmdvfyyjgwsf...
output:
7863
result:
ok single line: '7863'
Subtask #3:
score: 10
Accepted
Test #7:
score: 10
Accepted
time: 1ms
memory: 3772kb
input:
200 186 bmtexhhnkxtturdmbdwlnojqbrgmfsldftmxfuhwcsfvhqrwtyxahyaeqhdmptdzatiusqlzplnpwwpjtqruzwzfxrkmolppethnfcjahkggzrahuhjxtzzxftapeckzluzbawtqebmkuqvowxjjejyhlwviatpwsgrjlskzdemcjaikeqodtkzjfpuxjvajbecvzbfr iuaztcsejcanhhcxbceaivostovczsbsrqongikbzzrgrmubfqexqczjgzhdonhidpecjyugbbgsalfmosipjpumrgk...
output:
2783
result:
ok single line: '2783'
Test #8:
score: 0
Accepted
time: 2ms
memory: 4592kb
input:
200 91 babbaabaaabaabbababaaaaabababbaabbabababbabbabbaabbabbbabbaaabbbbbaaaabbbbbabbbbbbabaabbabbbbbbbabbabababbbbbbbaabbbbbabbaababbbaaababaaababbabbaaabbbbbaaaaaabababaaababbbababababbbabbbababbbababaabaa aabaabbaaaabbaaabbbbbbbbaabbbaaabbaabbabbababbabbbbbbbababbbabbababbbaaaababbbbbbbbbabaaabab...
output:
9267
result:
ok single line: '9267'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4300kb
input:
200 150 nbosezhgtlbulcqhzxmsekhmlwjxdnykhhrppccxytopamjpnmmlwjnvzxmlmzbgonxrfjnbehezhgtlbulgvjewofqnuurfjngckhhreqocuonxrlpthohchzzuatphchzwumrbokiqfbsbehnxsekhcbyoighozeesdxrbgonxrthozeebclvtpptlyjfgicbgbiko fvzctlpthoqfbssekhcbyoikzeexsezhgtlbulchhrebswwfgjjqxdnmtpotlpwcxytopauafopamjpnmzxmlmzbgon...
output:
7551
result:
ok single line: '7551'
Subtask #4:
score: 10
Accepted
Test #10:
score: 10
Accepted
time: 16ms
memory: 17348kb
input:
1970 76 dbajnykavlpizxpttpyxdtospawwemltpdearvnatpwekllfrwdelahxyilixhccmsukvusqodalaqqrxnyufonqzubxmddmryuysetyxlqrrepcajjhtoriwliaubkocbkyfwvdsuchvtxnhytznlmkzggxmolwkrwqjyhvnipugloyrpnplaokjtlwijwbdzttpeqjqdfqgtnlmkzggxmolwkccgorxwpipugloyrpnplaoubxmdoslibzcwbgqygqjmhpfbiggjanvjamjbwkcpzoucifnkjo...
output:
99038
result:
ok single line: '99038'
Test #11:
score: 0
Accepted
time: 17ms
memory: 18068kb
input:
2000 1800 vagekztgqyfqacujtmjjdggeisvtokooiolvurvumezuhipwklzgpivjrtfscnnsmbaumbnvwfrafjhrsotdfuhkafprhzrtjhjqmgduylebgxjqgmwtqocgthlxcjbxjhhpwaagzdpwmvagekztgqyfqacujtmjjdggeisvtokooiolvurvumezuhipwklzgpivjrtfscnnsmbaubvnmmftofygcvjsnotectmvyyagrpdgtcnwduojcrzwdsvqutkizcedhuqupwlrnlerheesueheorqfrf...
output:
359745
result:
ok single line: '359745'
Subtask #5:
score: 10
Accepted
Test #12:
score: 10
Accepted
time: 19ms
memory: 29492kb
input:
2000 110 cctdrvumnyzeieuzynrhpgdjhtblkwegiqspeqdvlfquembvbgkbxbxqxkzcrejmjybxpaajjbahvnllhsnwqhwbodppwugaglhiccqgwfrqwrrtzvarjphzdvpanlilvvubyzfpinkncmusfpeythsyaqehcpsqeoarrjesmszoxjdwokscxiopdvlrrcatthspslqeteanbgvonavsekcjlxzqkdknewqwkzlrkogaqarlookpwmdbglitjpljgkskomjlpjaxnqneorxlvaacsepppualnwg...
output:
204737
result:
ok single line: '204737'
Test #13:
score: 0
Accepted
time: 28ms
memory: 35200kb
input:
2000 1568 bbaaabbbbbabbbbbbbbabaabbbbaaabbbaaaabbbabbbbbbaabababbaabbabaabbabbabbbbbbbbbaabbaaaaaaaaaaaaababbabbbbababaaaaaaaabbababaaababaaaaaaabbbbaaaababbabbaaabaaaaabbbaabbbbabbabbbaabbbbabbababbababaaabbbaaaabbaaabbabbaaaabbbbabbbbaaabbbababbbaaabbaabaaaaabbaabbabbabaaabbaaaaabbbabaaaaababaabbb...
output:
675034
result:
ok single line: '675034'
Test #14:
score: 0
Accepted
time: 34ms
memory: 53880kb
input:
2000 1344 lolkxicffjoahkfdggddidecuqrfpfooutddnzbcazpcocgubmrigntptbyvztzqgicupxqkjakctdgmbqtfljxesdkumgzypjteiomnavydabegdsueyupxucuopzhucgrbipveldsgvdzxbtskfoficlremrcxzgnhkumgkqhkgrvdabegdsueyutemrcxzgnhkbkqhylgoldsvtgbljrmcbicgqshbetgofdjcxzlysumcfxpcovccfclgjltgmjvwlgghxzvwlgghxzhanmfwhlhxsvrno...
output:
880113
result:
ok single line: '880113'
Subtask #6:
score: 0
Wrong Answer
Test #15:
score: 10
Accepted
time: 0ms
memory: 6444kb
input:
136531 132287 dqkgbnnyzwmbzckupyuuupmenzjfpooutxplglbcqcyeyniuzhgecanatlvlfowlzqjrztednqbhopdrxaaephxnbfaqqfoqovicxazopnkttwzqvlyqrgistvpetfmhhughbqrncmrdbgmyfmivuxbwtuqbrqazuyygcxxgcragzwwxoxqyvpzugywirksslmhsspzountdivthtkvvdqhuoncsdrcewhqkptcwfuysrhqkgrivpckevgbejvwryjtsglmditbbjtxqubwruuqngjugbu...
output:
561550095
result:
ok single line: '561550095'
Test #16:
score: -10
Wrong Answer
time: 16ms
memory: 26936kb
input:
150000 121497 zngvmoixlvkgnadwokornampshpamkzttdsrlrdpljvnyhtumgbjrszxmlbjvuqqilfbwzozrbrofqdiwivrtylbupfvinlggpqojtpqnyjmyisydgzwcpicsacutzkpcttcktknqmvhjvvwkomytrhajtifdqldcfnhhwaavxfqtazukudojiyhxpxqoasmlvfbgavfdamyvdapmlxjvxrzvldbthtagauvczpuofglawxdlhvfughisxfxhskuuybyipbwxauxuytsagjronxoimcbzd...
output:
-831888988
result:
wrong answer 1st lines differ - expected: '3463078308', found: '-831888988'
Subtask #7:
score: 0
Wrong Answer
Test #17:
score: 10
Accepted
time: 192ms
memory: 101136kb
input:
93376 10006 qvajyijbvmbtcgejthwkwatplbtmscyqqlbjmooteoyzbushasbdruqbwsvdjwzwnfzkawoaqwwibibmsnmnbinktjybibswordjyxipmonbqujxmexlgnchbiqsalrrlnupdhaxvaehcnbjsmcypcakmmengrpogkisfrqghzuakdwdyipuioibvatllelgtqaeqnnmcqcooftbyvjbrfyczwmbiuccckfgdjkdhfdnygsmpspulqwlaorrepzauxbmwpyfqzkkgjyenyfqpulqkhbuegic...
output:
833972344
result:
ok single line: '833972344'
Test #18:
score: -10
Wrong Answer
time: 115ms
memory: 55120kb
input:
100000 3453 klyarstaybbaawhfordfxixwdlbxplhsequnbxtfmeanqfqimnkbcyqqyedrdtpstcddekspidolwgrqelojswgdfnaepcurhsyhvtdwfgufebqjrcyizbinzlntltteasxpwybvkiowzrdfwqybqglvtakkkejwiuvgypdtjycxiqrjfpwitfkrqkifjmxwzfpqgvvhdjfcfufqzxsnslakggtbtbzgrakleovglwbwhayczuygizjvsncrchniozxywswpchtohckqulsvytglehfhgtmk...
output:
332515783
result:
wrong answer 1st lines differ - expected: '246347135', found: '332515783'
Subtask #8:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 40ms
memory: 34756kb
input:
90081 61832 lqqwzyiwccivztgzvdcjowmgtohjstttigxkkciexmyicxputfgudxdwemcpnnforfltonoeevwxptmbzvelckmgmboebsmfqgvxwhgdlwezreycawmjgnlinxzjsbaqjafsrwhngmorjjubzbwynwgblayrduekrmrenvcuqdmnebsjqvhgcugnwppxtbuuekizxwcpvsusxmzmhzdsmlurhzugnitxtplmsefrsihjdvroaihlluqtttthcyyuekitefhcjcrwrcricypqhehanczcqarp...
output:
1746629137
result:
wrong answer 1st lines differ - expected: '1742191016', found: '1746629137'
Subtask #9:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 85ms
memory: 51600kb
input:
148067 68475 ndqltwlfnbfgjjrxfzwzlxjwuytfnmgkoozbgxmjhagcxowjeowjshohauryuvbhyijzktzzjnffhccmufbutucqpymbncwdopfziqpdcxqnkgwqekmyfxfftyzmwuyutgddadhmtteqefmbwpuauvsffbcqjhjwukvpleaykjajfdxhcspygwkikuwmtnjhjgxoaktshigoysxhrjjlptordbzoumukatnlzygzcykbnxgvlevngkwygjqrpyaodfutjhyyfygjccqkyjnzebcujwvvokd...
output:
1154937885
result:
wrong answer 1st lines differ - expected: '5449905181', found: '1154937885'
Subtask #10:
score: 0
Wrong Answer
Test #23:
score: 10
Accepted
time: 5ms
memory: 6392kb
input:
142928 139024 jdgusjdfvxvfdtvgwwumkrnhgpckfgeoagwnspjyiexkkgudqtkxbeprmpvzfsdtoexmccgqmgewithttrtoceddynvnvhurikgwhvdibmyaokzysmyrjxbwymdyskhsdhnhhbhoeyzsepiyvebfyojfxzlhrxozvsvzdmlggrtbyemqcxixqnmzscepaoogdxfdrvbwxxscokuucdycppvssnckvazqoutebossriaxuhnesksxzycabccoafbluystrytufwxhhdrcfumanheulnbgph...
output:
542881204
result:
ok single line: '542881204'
Test #24:
score: -10
Wrong Answer
time: 6ms
memory: 3668kb
input:
150000 101453 bbbaaabbbabbbaababaabaaaababbbbbaabaaabbababbababbaaaababbbbbaababbbabbbabaaaabaabaaaabbbbabbababbabbbaababbababaabbaababbbbbbaaaaaaabbbbaaabbababbbbbbbbbbbbabbbaaaaabaaaaabbaaabaabbbbbaabbbaabbabbaaaababaabbbaaaabbbaababaabbbaaaabaabbbabbabbaaababababbaaabaabbbabbbbbababbbbbbbbbbbaabb...
output:
629989533
result:
wrong answer 1st lines differ - expected: '4870040636', found: '629989533'