QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296238 | #7955. Tandem Copy | defyers# | WA | 1ms | 6756kb | C++17 | 2.2kb | 2024-01-02 15:36:41 | 2024-01-02 15:36:43 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using ll = long long;
using pii = pair<int, int>;
string condense(string t){
string res;
for(char c : t){
res.push_back(c);
if(res.size() >= 2 && res[res.size() - 1] == res[res.size() - 2])
res.pop_back();
if(res.size() >= 4 && res[res.size() - 1] == res[res.size() - 3]
&& res[res.size() - 2] == res[res.size() - 4])
res.pop_back(), res.pop_back();
}
deque<char> a(res.begin(), res.end());
while(a.size() >= 3 && a[0] == a[2]) a.pop_front();
while(a.size() >= 3 && a[a.size() - 1] == a[a.size() - 3]) a.pop_back();
return string(a.begin(), a.end());
}
const int N = 1e5 + 11;
typedef unsigned long long ull;
ull X = 145849, ps[N], pt1[N], pt2[N], pw[N];
int R[N];
int f(string s, string t1, string t2){
if(s.size() < t1.size()) return 0;
pw[0] = 1; for(int i = 1; i < N; i++) pw[i] = pw[i - 1] * X;
ps[0] = 0; for(int i = 0; i < s.size(); i++) ps[i + 1] = ps[i] * X + s[i];
pt1[0] = 0; for(int i = 0; i < t1.size(); i++) pt1[i + 1] = pt1[i] * X + t1[i];
pt2[0] = 0; for(int i = 0; i < t2.size(); i++) pt2[i + 1] = pt2[i] * X + t2[i];
for(int i = 0; i < s.size(); i++) R[i] = s.size();
for(int i = 0; i <= s.size() - t1.size(); i++){
if(ps[i + t1.size()] - ps[i] * pw[t1.size()] == pt1[t1.size()]){
R[i] = i + t1.size() - 1;
}
}
for(int i = 0; i <= s.size() - t2.size(); i++){
if(ps[i + t2.size()] - ps[i] * pw[t2.size()] == pt2[t2.size()]){
R[i] = i + t2.size() - 1;
}
}
for(int i = (int) s.size() - 2; i >= 0; i--){
R[i] = min(R[i], R[i + 1]);
}
int ans = 0;
for(int i = 0; i < s.size(); i++){
ans += s.size() - R[i];
}
return ans;
}
void solve(int TC) {
string s, t; cin >> s >> t;
t = condense(t);
#ifdef LOCAL
cout << t << endl;
#endif
int ans = 0;
if(t.size() == 2){
string t1 = t;
reverse(t.begin(), t.end());
ans += f(s, t1, t);
}else{
ans += f(s, t, t);
}
cout << ans << '\n';
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6116kb
input:
ACGCG CCG
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6260kb
input:
TATCGC TTCCG
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5636kb
input:
ABCABC ABC
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 1ms
memory: 6304kb
input:
ABCABC ABCABC
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 6452kb
input:
FUSBX UUUUUUUUUU
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 1ms
memory: 6076kb
input:
IWN NNNNNNNNNN
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 1ms
memory: 5612kb
input:
RMRMRMRMRMRMRMRMRMRMR MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMR
output:
210
result:
ok single line: '210'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4308kb
input:
TY YT
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 1ms
memory: 5604kb
input:
WZ ZW
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4440kb
input:
SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBWGVXPWAXMSBSB SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS...
output:
1121
result:
ok single line: '1121'
Test #11:
score: 0
Accepted
time: 0ms
memory: 6072kb
input:
TGJPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPX PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
897
result:
ok single line: '897'
Test #12:
score: 0
Accepted
time: 0ms
memory: 5808kb
input:
MKZOLDYLGAULULULUGASEAOZVIHNMRGKZQEIQYTGEMLBMAULULULULULULULPNERGKYZARPULULULULULAOZLQGYHULULULULZKYZUXEBVXZBULULULULULULULULULULULULULULULULDCEXCSTHQRULULULULULULULULULULULULULULULULULRDMPBDULULULUFVXWEMTULULULULULULULULULULULULULULULULULULULULCLULULULULULULULULULULULULULULULULULULULULULULULULULULU...
output:
46504613
result:
ok single line: '46504613'
Test #13:
score: 0
Accepted
time: 1ms
memory: 4500kb
input:
VEPZEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM...
output:
43715406
result:
ok single line: '43715406'
Test #14:
score: 0
Accepted
time: 0ms
memory: 6260kb
input:
HKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKFBIAHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKIHKHKHKHKHKHKHKHKHKHKHKBHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHK...
output:
45393402
result:
ok single line: '45393402'
Test #15:
score: 0
Accepted
time: 1ms
memory: 6164kb
input:
ZHJDKBQNJPACACACACACACACACACACACACACACACACACACACACACACACEZACACACACACACACBLCRDQEACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACGUEKSAJOFACACACACACACACACACACACACACACACACACACACACACACKHUIOCNKXMKUOKACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACRACACACACACACACACACA...
output:
45452856
result:
ok single line: '45452856'
Test #16:
score: 0
Accepted
time: 1ms
memory: 6104kb
input:
CXQKRAVWKJFOHVJVMNSBGOEJZFAESPYDZCLUOHLBQEHIDLWQWQWQWQWQWQWQRETGMKPFZQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQSWLXQVWQWQWQWQWQWQWQWQVEHITSVRXBHEWCARSTKQZERXDNJTXGIHTBMCVYSKPSFYIDRGAIEVSTJGUBGMSQFXGWQFHBCTMGOWQWQWQWQWQWQWQPEYDLNUGDIOEKHRNSROPWQWQWQWQWQWQWQWQWQCMSPXODTIKOZYPFHROYFECRUJDWQWQWQWQWQWQWQWQWQWQJUWJK...
output:
49328004
result:
ok single line: '49328004'
Test #17:
score: 0
Accepted
time: 1ms
memory: 6552kb
input:
CBFKLKDEFBGHCEAMJIKGMLJFDKFIDJAKIADCHEJAMJBIFBJCEJCKDFLAFMEGDAMHLDCFGDBJDKLGIDCBMAFBMLFDJGAMLEAHBCIDLFJKCGHILCEDBLKIDMJDICBMFKLDKGLKMLFGKIDGHJIKJHBAJFMLJMEHGFEGAHBJLEBHKAJCKADEFGIEMGKCGMBEJKCFGAIMJBDGFHEMAELCDHCFJGAKEBJFHBDMKEMCJIKLGMCFJGDFLBACHECJMECIDGBKJHMEHILCKIBCLIFMHJFDGAILEBGIAJIFCILFJBLFALGB...
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 6500kb
input:
JIDABCASN ABCBABCBC
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 6648kb
input:
ASFJABCSFN ABCABC
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 6240kb
input:
ELUNVXDGQHAYMVWAYBQUJIMOFNOVPTALPHTWCPDMALKAZEAPXFMZCTLKHFIYPUOYKIVLNGHTXSJNIHZURWNYNXBMWOVZYXAQDKFWTHCYVQNFMNIQRFWKTQYHAVJOXNMPTIRWLJXERAWFSZKVOWTNXOTXSTWIGNCEKWDEADLSWHCQDPECUXEKAFEHPKHLTHPFYLUBXGMKENZTOQZKAESFNIQAKUVWPNQAPEHAVIWFAOIXMBPJITYOLTKYGAWKBDOZJUFOVCPGDFZLFQIGEBDEMNUPYEKWSCGDOUWEOJXMAHGZ...
output:
0
result:
ok single line: '0'
Test #21:
score: 0
Accepted
time: 1ms
memory: 6756kb
input:
QAUFICKQDARDZBSWEMXFDPAUJVBDHVTAZDJRMXVNQYBWJLOSONYGXZNKURCGHMXFGZSQIGSRMPSDJGLFUWZJVMDAGUFOXIFHCTWLMLTSMJLOSCLYEYEXZKBEVMORHAGMKCMPIBZXCMNVOEXBJOYBHMVZHBYMVBFLNZPSDZBUEOCZJHZEAUZREVNLIDNHCYBJVBGPSVKSNHTUONLREOIPVTRXIZAYRAPZVYENZVXYIWZLQOVTGZPUAMBSWFVIUHJNACLOFVGNSKPMTSYLVTUIPWKVJYLWKGWZBGCEBVDYTVYI...
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
BIUBEMOYSEHTDAYBGSTIEGZAFLQFRKXZHKMLIZORXMYPRIPZVSBPVJYHMFBKVIFXAYFJQCPEGPERASKTJFNYVXNXALJGSABVIEURYVHBVEIAZUXSPANGABQRZHTKQJBTEWLGSTAMEFSZHBZOFDWPXMAZYDPIWXSIMYELONUAJXHBZWSFKEABYQKFRIWYVIFQBLSQJKRTLONRQBJARCKJTKGFIWFRDNYICDQXLIJUVXZNJKGQTEUXGHAEYHWBXYCOSMTPIXRYKIGQLMJCYDIKSPZMCSEHWRHAXEQCZYHXOSWU...
output:
0
result:
ok single line: '0'
Test #23:
score: 0
Accepted
time: 1ms
memory: 5872kb
input:
TGZBZAEQDTWERZFYHZPTVHCLFIVBCOTZAKVSXYUXHLCRIDGLJEWULEVJEZSXUCPXBPCVLACGKCLNRPLVPUWKSOWXREVIHXDSQWCLYEBHOMDYHGQVZADJOSQMBUSKGVEQOMKLBCWNUGOLFZXEPRCZKWJXEZVOWNGVEDQYJIECTMQHXOVPYZDUBZMFBJWZHMAVMWZPFUYXVKLERIPRVMWYUSOZFYAKDZMQDEUSGMVSDHBYFIPOGKIAYHRTBYPGOXMGYSRHWRIZBIZWQITLFKYRWASGAPLUFMIUZJTRVYJLZCQV...
output:
0
result:
ok single line: '0'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4384kb
input:
AIEYDRNKWSEGPLDXVHXFMSJGUQFVNRXTQPVQZHWEHUBVAUPUTCQJYTEBJWEULSDIPVQPNGIODAZRSUQFYEMZEQDALGHMNLETNXTNECTOQGIEVAJFPATYDXIHEGAPMRQUTGCNUTJHFSZJDIUFXHBEMWHDCIYJUGYTHOCEZRTHXWHEWFIVONEGUMKGIENRALWBJLSQAYOFZLBXMAOXPIMTSJEFZEGNMQSPUCZHMRDNVPKJVATROZAQGFOWCTUVKOMVWDAXLRMOZHNEAHUOKEDSYJRAWQLMRUDQCXOTBQOXGRBG...
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 1ms
memory: 6680kb
input:
ZJPVDHIXEZCWVXWOZYEILQHRPRQZORZQBLIXHCKPGJYIZDBZDENDLPHYRMAONHOAKTHMTKHJBFJYRKQTHLZHTPKJQSXZEHRQGBPRWDMFHWTJZTJCEYLZAJCMEKXHJORTJMFHNAEMJBOLTUYXVLXCZFUNRIGVESCBHSVGUXRMUKIRCAXCIYSCLYCBADRGTQGZTWDBMOEWHPFRXPISNECTFVQRJZUJRGLYMOWHFZDXAMHTCRLXPOMKCXSVGKHJVLDRAHDYMWHURFOJCYPLVYLVUMAZDEHCNBOQWBYIPMDYXUTO...
output:
0
result:
ok single line: '0'
Test #26:
score: 0
Accepted
time: 1ms
memory: 6340kb
input:
QKNDNBUGVUTWQVNETHRWEUWFHJEYGKLAHKSALTHQCTSPFOUMTGWSGCLYIQDPERLHMXZQIAFBVGDQRJWPCFTRQSNRYVPRYCHQUBCYHRAMQXFBXMVXCPXVOIFUYZVOAFMARDSEQPENUAEQWVNBMVJXTBKYTEMCSOPHSRDMWZPQLWVLIAPWNRVQCNBEXGWZXOFRKBJFCUQWNCRURAQLFPSXBSUOFQCRGCVGQYDHXBESHMZJOTLXAUOECHBOEDHRIJRAHELBYXWSQGPXITSRKDNFXSTZYXHSGIPWAZMDUZIXVJGU...
output:
0
result:
ok single line: '0'
Test #27:
score: 0
Accepted
time: 1ms
memory: 6156kb
input:
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0
result:
ok single line: '0'
Test #28:
score: 0
Accepted
time: 1ms
memory: 6216kb
input:
CBABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0
result:
ok single line: '0'
Test #29:
score: 0
Accepted
time: 1ms
memory: 6208kb
input:
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0
result:
ok single line: '0'
Test #30:
score: 0
Accepted
time: 1ms
memory: 6504kb
input:
INBHJGLCDJGRSNWHTXFEGIAWVWXROMSYXZTFCBHWTIXCBZEJZFGPZKAXTJFQVDTANSJCETHIPGHFELUHBTZRIOBTMLYMRCQDVNCAUIXQTZKAGMPWLUVJFVAZMRXAOSDYJHYKISJTSMTQYCIFTNHECWDYIWGEVZMLBMUJYOKALXYVUTWVBKDBRIUJGTKMUFHWZOCPNIYONVYHVRGPFCWFJQKDLRXFOGSOXEZBIZEWLNROMXZWIFHDCHFEDMUITXCPLTWQCBLXFJQUZSOHXKLFRPTYPNODIXMSUXNSBQHKAWCJ...
output:
0
result:
ok single line: '0'
Test #31:
score: 0
Accepted
time: 1ms
memory: 6456kb
input:
TFQCDUYXLOYHPUIHIKATDYXRVKLWDBGSHPQTVSBKHONRAKTDJSERAIODSCQOEKCTHAGXRVPHEMOTUBETNUCWDHEOWJPMGKTZCPWVPGRBTWISZHPQABQULBKDQURQHRCMPEKHOLGTQNHFXWPXARBSJNLEPYZVEJSYFVYAQIULITNEFKLGMLWXCVGJSBTNRBQTXOACDVHYLKWZVFAJDNLSBEOWPTZSOGVTJACIUNZJTANFIGQMFLMHSATMPXEOVXLGMOEUZYHNTHVKOMGLJRSMVXQYVOMJEHZGNJVNOGBUCKQF...
output:
0
result:
ok single line: '0'
Test #32:
score: 0
Accepted
time: 1ms
memory: 6196kb
input:
QWKDETMOTCFHWAKLRYCJLQBHMGXEBFEYIFIQYKOURSTXEBXUETDXAQBYKSJIZKWMSIAPSYZQICSJBPSAKUPEFJLMODTHSNBIHLKNGMRQNYLFTVPYUQDPUVINLIMRGSWULQDYQVKRDWHAVQARIWXPFRBFZDFPZVFMUFDRIPSWEQYEQGOXHEOGHEGDRAGHTUYMQJHKGREXHQATPHWGAHYIVAFIQHOPYSRENZKAHBCFVPZKWPIGNIYOUXFQKZURTKIHFOJBMHOLFDWOEJHDVLWZEPDVMCSPWKJEXLEKGBUCOZDI...
output:
0
result:
ok single line: '0'
Test #33:
score: 0
Accepted
time: 1ms
memory: 5944kb
input:
PMONBRZUXLXOMICDOYGCDRILAPJCUISVFCWUXHDUBXTVPGVKAUGYBDRBMXNDWHMSRZFMRXSVDSNZQXBMDUNEYZDWOKAERTSMEYJCLFWYLNHCOQKDLTJPMNCJWLZGKVHERNZQYSFTQGSXDYQRWSDFMRHCFEYHEZBENBQRYMPXDWIBRFGRIGMPWNISLDIYBKIJKTSVJRHZUOWZONHAXTDZIHSABHFXYWLJTADJGREOVSJYTAIUSAJPQUFNXBZVTWONZUODJBNGXFDAODBJGHRQXLMBWTUXFEVZWLJPINSBMGTJ...
output:
0
result:
ok single line: '0'
Test #34:
score: 0
Accepted
time: 1ms
memory: 4980kb
input:
IGOCPESZSKCGJBLHDFKLNBENRFXNQAYFVLNWPTDYFANZMCARIMZKEPWQTYCPJILYNOVJSFEZWOBNJKGSEGFJIQOHUYTHXVKUAISVPRMUXAKXZVJWQMFNWLAQENGTORCLDTRBNZLENSKQFLGMJHWBIUMAQJCUTWRMXYKLXWLSNDSVITYZHCBYGJSRKHPUBQCZSIMEROWVYLAQNLQOYEMGSLTNQETDXZWEQUSMCGALKITMKOIFDQRWYCUTWJVIMSTCOADHIJPLWRKXHGNOMSGPXFADBMZTILHROCSARTLPDRFC...
output:
0
result:
ok single line: '0'
Test #35:
score: -100
Wrong Answer
time: 1ms
memory: 5664kb
input:
UNINININININIUNININIUNINININININININIU NINININIUNININIU
output:
0
result:
wrong answer 1st lines differ - expected: '216', found: '0'