QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760546 | #7955. Tandem Copy | SanguineChameleon# | ML | 355ms | 1029932kb | C++20 | 1.6kb | 2024-11-18 17:31:27 | 2024-11-18 17:31:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define mp make_pair
#define eb emplace_back
#define pb push_back
typedef pair<int,int> pii;
const int mxn=2e4+2;
int dp[mxn][mxn];
int32_t main() {
ios_base::sync_with_stdio(false);cin.tie(0);
string s;
string T;
cin>>s>>T;
string t="x";
t[0]=T[0];
for(int i=1;i<T.length();i++){
if(T[i]!=t[t.size()-1]){
t += T[i];
}
}
int ss=s.length();
int tt=t.length();
for(int i=0;i<=ss;i++){
for(int j=0;j<=tt;j++){
//length of suffix (in S)
dp[i][j]=1e9;
}
}
// cout<<t<<'\n';
s="$"+s;
t="$"+t;
// dp[0][0]=0;
for(int i=0;i<=ss;i++){
dp[i][0]=0;
for(int j=0;j<=tt;j++){
// cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
if(i+1<=ss && j+1<=tt && s[i+1]==t[j+1]){
dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+1);
}
if(j+2 <= tt){
if(s[i-1]==t[j+1] && s[i]==t[j+2]){
dp[i][j+2] = min(dp[i][j+2], max(dp[i][j],2ll) );
}
}else if(j+1 <= tt){
if(s[i-1]==t[j+1]){
dp[i][j+1] = min(dp[i][j+1], max(dp[i][j],2ll) );
}
}
}
}
int ans=0;
for(int i=1;i<=ss;i++){
dp[i][tt]=min(dp[i][tt], dp[i-1][tt]+1);
// cout<<dp[i][tt]<<' ';
if(dp[i][tt]==1e9)continue;
ans+=(i-dp[i][tt]+1);
}
cout<<ans;
}
/*
ACGCG
CCG
TATCGC
TTCCG
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5588kb
input:
ACGCG CCG
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5636kb
input:
TATCGC TTCCG
output:
6
result:
ok single line: '6'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5552kb
input:
ABCABC ABC
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5584kb
input:
ABCABC ABCABC
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
FUSBX UUUUUUUUUU
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
IWN NNNNNNNNNN
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 0ms
memory: 7600kb
input:
RMRMRMRMRMRMRMRMRMRMR MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMR
output:
210
result:
ok single line: '210'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
TY YT
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 5624kb
input:
WZ ZW
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 11736kb
input:
SBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBSBWGVXPWAXMSBSB SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS...
output:
1121
result:
ok single line: '1121'
Test #11:
score: 0
Accepted
time: 1ms
memory: 10000kb
input:
TGJPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPXPX PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
897
result:
ok single line: '897'
Test #12:
score: 0
Accepted
time: 4ms
memory: 110180kb
input:
MKZOLDYLGAULULULUGASEAOZVIHNMRGKZQEIQYTGEMLBMAULULULULULULULPNERGKYZARPULULULULULAOZLQGYHULULULULZKYZUXEBVXZBULULULULULULULULULULULULULULULULDCEXCSTHQRULULULULULULULULULULULULULULULULULRDMPBDULULULUFVXWEMTULULULULULULULULULULULULULULULULULULULULCLULULULULULULULULULULULULULULULULULULULULULULULULULULU...
output:
46504613
result:
ok single line: '46504613'
Test #13:
score: 0
Accepted
time: 0ms
memory: 110988kb
input:
VEPZEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM...
output:
43715406
result:
ok single line: '43715406'
Test #14:
score: 0
Accepted
time: 4ms
memory: 109608kb
input:
HKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKFBIAHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKIHKHKHKHKHKHKHKHKHKHKHKBHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHKHK...
output:
45393402
result:
ok single line: '45393402'
Test #15:
score: 0
Accepted
time: 0ms
memory: 111724kb
input:
ZHJDKBQNJPACACACACACACACACACACACACACACACACACACACACACACACEZACACACACACACACBLCRDQEACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACGUEKSAJOFACACACACACACACACACACACACACACACACACACACACACACKHUIOCNKXMKUOKACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACRACACACACACACACACACA...
output:
45452856
result:
ok single line: '45452856'
Test #16:
score: 0
Accepted
time: 4ms
memory: 113468kb
input:
CXQKRAVWKJFOHVJVMNSBGOEJZFAESPYDZCLUOHLBQEHIDLWQWQWQWQWQWQWQRETGMKPFZQWQWQWQWQWQWQWQWQWQWQWQWQWQWQWQSWLXQVWQWQWQWQWQWQWQWQVEHITSVRXBHEWCARSTKQZERXDNJTXGIHTBMCVYSKPSFYIDRGAIEVSTJGUBGMSQFXGWQFHBCTMGOWQWQWQWQWQWQWQPEYDLNUGDIOEKHRNSROPWQWQWQWQWQWQWQWQWQCMSPXODTIKOZYPFHROYFECRUJDWQWQWQWQWQWQWQWQWQWQJUWJK...
output:
49328004
result:
ok single line: '49328004'
Test #17:
score: 0
Accepted
time: 127ms
memory: 866788kb
input:
CBFKLKDEFBGHCEAMJIKGMLJFDKFIDJAKIADCHEJAMJBIFBJCEJCKDFLAFMEGDAMHLDCFGDBJDKLGIDCBMAFBMLFDJGAMLEAHBCIDLFJKCGHILCEDBLKIDMJDICBMFKLDKGLKMLFGKIDGHJIKJHBAJFMLJMEHGFEGAHBJLEBHKAJCKADEFGIEMGKCGMBEJKCFGAIMJBDGFHEMAELCDHCFJGAKEBJFHBDMKEMCJIKLGMCFJGDFLBACHECJMECIDGBKJHMEHILCKIBCLIFMHJFDGAILEBGIAJIFCILFJBLFALGB...
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 1ms
memory: 5868kb
input:
JIDABCASN ABCBABCBC
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 5784kb
input:
ASFJABCSFN ABCABC
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 4ms
memory: 105560kb
input:
ELUNVXDGQHAYMVWAYBQUJIMOFNOVPTALPHTWCPDMALKAZEAPXFMZCTLKHFIYPUOYKIVLNGHTXSJNIHZURWNYNXBMWOVZYXAQDKFWTHCYVQNFMNIQRFWKTQYHAVJOXNMPTIRWLJXERAWFSZKVOWTNXOTXSTWIGNCEKWDEADLSWHCQDPECUXEKAFEHPKHLTHPFYLUBXGMKENZTOQZKAESFNIQAKUVWPNQAPEHAVIWFAOIXMBPJITYOLTKYGAWKBDOZJUFOVCPGDFZLFQIGEBDEMNUPYEKWSCGDOUWEOJXMAHGZ...
output:
0
result:
ok single line: '0'
Test #21:
score: 0
Accepted
time: 4ms
memory: 105572kb
input:
QAUFICKQDARDZBSWEMXFDPAUJVBDHVTAZDJRMXVNQYBWJLOSONYGXZNKURCGHMXFGZSQIGSRMPSDJGLFUWZJVMDAGUFOXIFHCTWLMLTSMJLOSCLYEYEXZKBEVMORHAGMKCMPIBZXCMNVOEXBJOYBHMVZHBYMVBFLNZPSDZBUEOCZJHZEAUZREVNLIDNHCYBJVBGPSVKSNHTUONLREOIPVTRXIZAYRAPZVYENZVXYIWZLQOVTGZPUAMBSWFVIUHJNACLOFVGNSKPMTSYLVTUIPWKVJYLWKGWZBGCEBVDYTVYI...
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 116ms
memory: 420444kb
input:
BIUBEMOYSEHTDAYBGSTIEGZAFLQFRKXZHKMLIZORXMYPRIPZVSBPVJYHMFBKVIFXAYFJQCPEGPERASKTJFNYVXNXALJGSABVIEURYVHBVEIAZUXSPANGABQRZHTKQJBTEWLGSTAMEFSZHBZOFDWPXMAZYDPIWXSIMYELONUAJXHBZWSFKEABYQKFRIWYVIFQBLSQJKRTLONRQBJARCKJTKGFIWFRDNYICDQXLIJUVXZNJKGQTEUXGHAEYHWBXYCOSMTPIXRYKIGQLMJCYDIKSPZMCSEHWRHAXEQCZYHXOSWU...
output:
0
result:
ok single line: '0'
Test #23:
score: 0
Accepted
time: 355ms
memory: 1029932kb
input:
TGZBZAEQDTWERZFYHZPTVHCLFIVBCOTZAKVSXYUXHLCRIDGLJEWULEVJEZSXUCPXBPCVLACGKCLNRPLVPUWKSOWXREVIHXDSQWCLYEBHOMDYHGQVZADJOSQMBUSKGVEQOMKLBCWNUGOLFZXEPRCZKWJXEZVOWNGVEDQYJIECTMQHXOVPYZDUBZMFBJWZHMAVMWZPFUYXVKLERIPRVMWYUSOZFYAKDZMQDEUSGMVSDHBYFIPOGKIAYHRTBYPGOXMGYSRHWRIZBIZWQITLFKYRWASGAPLUFMIUZJTRVYJLZCQV...
output:
0
result:
ok single line: '0'
Test #24:
score: 0
Accepted
time: 4ms
memory: 115560kb
input:
AIEYDRNKWSEGPLDXVHXFMSJGUQFVNRXTQPVQZHWEHUBVAUPUTCQJYTEBJWEULSDIPVQPNGIODAZRSUQFYEMZEQDALGHMNLETNXTNECTOQGIEVAJFPATYDXIHEGAPMRQUTGCNUTJHFSZJDIUFXHBEMWHDCIYJUGYTHOCEZRTHXWHEWFIVONEGUMKGIENRALWBJLSQAYOFZLBXMAOXPIMTSJEFZEGNMQSPUCZHMRDNVPKJVATROZAQGFOWCTUVKOMVWDAXLRMOZHNEAHUOKEDSYJRAWQLMRUDQCXOTBQOXGRBG...
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 23ms
memory: 238044kb
input:
ZJPVDHIXEZCWVXWOZYEILQHRPRQZORZQBLIXHCKPGJYIZDBZDENDLPHYRMAONHOAKTHMTKHJBFJYRKQTHLZHTPKJQSXZEHRQGBPRWDMFHWTJZTJCEYLZAJCMEKXHJORTJMFHNAEMJBOLTUYXVLXCZFUNRIGVESCBHSVGUXRMUKIRCAXCIYSCLYCBADRGTQGZTWDBMOEWHPFRXPISNECTFVQRJZUJRGLYMOWHFZDXAMHTCRLXPOMKCXSVGKHJVLDRAHDYMWHURFOJCYPLVYLVUMAZDEHCNBOQWBYIPMDYXUTO...
output:
0
result:
ok single line: '0'
Test #26:
score: 0
Accepted
time: 28ms
memory: 230184kb
input:
QKNDNBUGVUTWQVNETHRWEUWFHJEYGKLAHKSALTHQCTSPFOUMTGWSGCLYIQDPERLHMXZQIAFBVGDQRJWPCFTRQSNRYVPRYCHQUBCYHRAMQXFBXMVXCPXVOIFUYZVOAFMARDSEQPENUAEQWVNBMVJXTBKYTEMCSOPHSRDMWZPQLWVLIAPWNRVQCNBEXGWZXOFRKBJFCUQWNCRURAQLFPSXBSUOFQCRGCVGQYDHXBESHMZJOTLXAUOECHBOEDHRIJRAHELBYXWSQGPXITSRKDNFXSTZYXHSGIPWAZMDUZIXVJGU...
output:
0
result:
ok single line: '0'
Test #27:
score: -100
Memory Limit Exceeded
input:
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0