QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697566 | #5085. Palindrome Type | AMATSUKAZE# | AC ✓ | 6ms | 21012kb | C++20 | 1.6kb | 2024-11-01 14:54:07 | 2024-11-01 14:54:10 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }
using pli = pair<ll,int>;
using pii = pair<int,int>;
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
const char* delim = "";
for (auto &e : v){
os << exchange(delim, " ") << e;
}
return os;
}
void solve(){
string s; cin >> s;
int n = s.size();
// start (0,n)
// end (i,i), (i,i+1)
// state (l, r)
// left : l, right : n-r
// if abs(right - left) >= 4 : ans >= 4
// --> abs(right - left) <= 3 is valid
// --> abs(n-r - l) <= 3 is valid
// --> -3 <= n-r-l <= 3
// --> n-3 <= l+r <= n+3
// dp[l][i] : r is n-3-l + i
vector<vector<int>> dp(n,vector<int>(7,5));
auto dfs = [&](auto sfs, int l, int r) -> int {
if (r - l <= 1) return 0;
if (!(n-3 <= l + r && l + r <= n+3)) return 4;
// r == n-3-l+i
int i = r - (n-3-l);
if (dp[l][i] != 5){
return dp[l][i];
}
int ret = 4;
chmin(ret,sfs(sfs,l+1,r)+1);
chmin(ret,sfs(sfs,l,r-1)+1);
if (s[l] == s[r-1]){
chmin(ret,sfs(sfs,l+1,r-1));
}
return dp[l][i] = ret;
};
int ans = dfs(dfs,0,n);
if (ans >= 4) ans = -1;
cout << ans << '\n';
}
int main(){
cin.tie(0)->sync_with_stdio(0);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3860kb
input:
aababaa
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
abccbbab
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
acmicpc
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
aabaa
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
abbaa
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
abcde
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
abcda
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
abaabba
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
bbbaaa
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
abbccba
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
abcabcb
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
bababbababb
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
bccaacacaaacaacaab
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
ienkzavpcizlzdhkhdzlzcpvzzknei
output:
3
result:
ok single line: '3'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
xebhsigufoeitoeotieofuygidshbx
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
dhnthbvccwreeksxyvrprgmtvxqsmfdpoqlwrgywdrrdwygrwlqopdfmsqxvtmgrprvyxskeerwccvbhtnhbd
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
iixcpzhlsmoymepzvowvhemuvyolonyylvxdnwkaqzoolugmguloozqakwndxvyynoloyvumehvwovzpemyomslhzpcxii
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
ktivgldiwuvvuwfuimxbwnfuxjbkveugxcddpjnnfliajowtcwuyjztglwqgcmozouefdssifakoqhhsfdtodowqmmypapymmqwodotdfshhqokafissdfeuozomcgqwlgtzjyuwctwojailfnnjpddcxguevkbjxufnwbxmiufwuvvuwidlgvitk
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
brawtvyoegtlxrsmihfugdhxevyofongrghnzcnqivjvuaogkvcryjqegqtlgiuxobmpfzfnwriqrywcuzvswknzreuekcaisiackeuerznkvsvzucwyrqirwnfzfpmbogxuigltqgeqjyrcvkgoauvjviqncznhgrgnofoyvexhdgufimsrxltgeoyvtwarb
output:
-1
result:
ok single line: '-1'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
bjrdlkkeuxwpuleskensyvgaoqpfqxpuiixwuhaohwgdjmvtsknsfwsvokdfhubqfyozhoqomytdxkoqdygvgcqdqaixhdyzkypllpykzydhxiaqdqcgvgydqokxtymoqohzoyfqbuhfdkovswfsnkstvmjdgwhoahuwxiiupxqfpqoagvysnerkselupwxuekkldrjb
output:
2
result:
ok single line: '2'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
xyrquyctbtomlifsvzqwszovnmwdxrvurmmmnqhqkxfxfkpcliydhoaxawcynyuhmjvzzcslaxjhjymugkxqzapbwrwbmpytehodisxuuwdefibqzkczcdzrfvkijcgcgnqlyljsffxjlabjmkelohkfoisxrudwatolrzwlhcispiubvynjfzruhjtbdwzfrnqkpnvwrfoofrwvnpkqnrfzwdbtjhurzfjnyvbuipsichlwzrlotawdurxsiofkholekmbaljxffsjlylqngcgcjikvfrzdczckzqbfedwu...
output:
3
result:
ok single line: '3'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
qcnwmzuexrrrhwsstqipfmfithltdizvmmsznmfkgydnuxhnnsetekbxtoqwyprkdllsasfgqivkgcavueoyqrxjhqhhhbunmffmakusvpfdufyqlpregopqgzxoarbmzibztvtqnythdrxrgoxpfmfllebnwccxndygarwnqpuviuopklerylflpgznlbkyeiggceuuvqpdkesxryorjtjroyrxsekdpqvuuecggieykblnzgplflyrelkpouivupqnwragydnxccwnbellfmfpmxogrxrdhtynqtvtzbiz...
output:
3
result:
ok single line: '3'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
oftswowkrbmtqnhocbhzylujkfczlllbqetptrzmvlhnbredslesyybigdirotugxpvsiwhfkotlfxqzkutiuwqabatrtnytcvllsuqcjlnqidquzlctitwjvpbpdbihwvsoqlszwhrhmjblvghfbdqwstlxuvfrrzhjkakjjbswlvhibonctdbozmltksmdswmeywphzhdkfnsgdhlxnmnmayhmruplsbpqzfzqpbslpurmhyamnmnoxlhdgsnfkdhzhpwyemwsdmsktlmzobdtcsnobihvlwsbjjkakjhz...
output:
-1
result:
ok single line: '-1'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
gflwyilnakfxxxbrebxqjyzoaxuqhxwncjmcsxpsjvrissbyuzjqfzpvzoppvoolqxxspwkjffbqzvrxpsnxsesrtkjqyxbpwyjmwtxeyyuzwnwlglkyqdrlncbnzdewdokcjjgkkajgnitvtevlhpwwrajrdopiebknksxushairudkazyhqufhuoazerkkswyfpxzjgcrxyxkyyihocmvzcwajnkvijtnytohbsbzzbsbhotyntjivknjawczvmcohiyykxyxrcgjzxpfywskkrezaouhfuqhyzakduria...
output:
2
result:
ok single line: '2'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
qpvpahejsenjqjravaqxyukdqfratgqkvlbxufhnlwybfpdcquzoqjrgoliiryugojxoedvtotrsygvayramijgoatzimxecjbqnglgxezrefofeghsqqagstfchdgkmkabsojpsiizpxetdnovfobykharmjbytcbnskfkunljkrfpevkkjmivvinhrqhmskamwhxqukbhcgwgdjqvnxyiuhxbaokniwpvswuiselzguynxhxnyugzlesiuwsvpwinkoabxhuiyxnqjdgwgchbkuqxhwmaksmhqrhnivvim...
output:
2
result:
ok single line: '2'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
vvpefnuxjwrigvnbfrusdhwtqqlpeqgbmvfricrtaiegdrikkeeolbhcrstxlzzxxgqfihbjrfrwyzgjelxpoetfzofmoejlmzsvjvgaaxxbzfkdqjuenqmoetauzlflnagwxowymvbnblstumyjemajfcdgolrbnazkovkcrlpuyhnuwneabgliipoycgbrgabuyozrbolawyuuoaupiiytxmrbuvscvvzvjymnmzpkyjgombduldpishlmedpbaoxmojzajonjztznwckhizraicomhdoktnwhwxkhlxsm...
output:
-1
result:
ok single line: '-1'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
eqejbhvitsyijlbloupxipxsczvunzmrprdsyadssbcemepcagclxzfzybunaghpzkkymnsfqujfaahbgjmdkreisyyuhfmgrwgdjaizvtextoybzmgkglualsvuzjdqfjwomgphaugvihzjthtbsqegkbckkfcpryddfsmhoseyzdivldwftcnedqqnvscothrycfhqylpzpzucetjyvxeznwokorzjyshayotwckxrjsvnnenkdtlqpadgtcpruzuspnqrxokiifxxmlhpgtiyvleopvhjwbemqwfpkqxu...
output:
1
result:
ok single line: '1'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
fsdarrxlmzsffruegoplsphgvvndlyissmujfrxrsrwyisergtcbiljgixlvxuprijbncagurcubuyucuyfelrmtoyqlufeeohrqhxnabhexiyzczhgkytgotybpeftunmnwlaxmjdlrdmvcteptzvhsvijzocwdqjzblypubaohmljipaboxjittrujvqmlbmommdjqfzxskgacjbsgmbziuwrsmefosucgzlwfmtxxczblatrputxrpqjduotoiwvijrnylmvnlyanrreombfduqhqecfpyczkvoiicfxn...
output:
2
result:
ok single line: '2'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
utwglhanestizpssmlspkuqfwsxehvcbqakdkkqoemyfbsyqeqfomxuirrpyotagtkjfubvapugrmejswqjjnftfykfodfuzrfeniaoywurkacdwsmhhtdolrnufrbbstiwgqyuqwqhhsjkpdyylrdzirvpkxqeqycyqbvhxlqgeaqvdqvqjzstsniekaicakdrnyynlotpqmmwckmojehdsshesrjtdmkrkkevaxntjbpolbcwilzcdigwbrrfddwpncnpbcildxbrbdpjorlsztqdlhiqmggzitqlxzway...
output:
1
result:
ok single line: '1'
Test #30:
score: 0
Accepted
time: 2ms
memory: 5120kb
input:
mjnrimbykkhyovdmoihymbmxrektnvxzhmsrzwpjiziwullivsjhvvgpbrioohpvukmtgeeofomzzxjxrugprngseoisxyqriemqirgnfsohsaelumcoziifyrawpqpzuerfvxucrjlllrxhezvdkejivjgmbynxcgczdxbwinitehakiyosczdzklnljaklinmlmojudrpjapujnkdrjgstufgdhqrpfdcrtmlydciesephosbxbtsxzyagqtwwzynumbtqddwxhnfvfiuibmfamijcdhaehozurumuxiug...
output:
0
result:
ok single line: '0'
Test #31:
score: 0
Accepted
time: 2ms
memory: 5076kb
input:
bhpkjaznrfnylldmqvvpnuhpkpwtdkrgugqdjpsaxfzkreyhbtyqoigaxetcrkiltzqeqiennfygmwopsogiwoiwubylnjyiiomawtomaosmmicgxkovawruzsipdgxlvmnrfdffryugiymhiddkzwgzqoqtvngszulgxrmrrgxzelhoomaqigrbxhuuudmwxxcwqqnhymheyquocuemdxpaemubpizofbkyuyfskozkgtbkohxtfotjapmpxldepqcjokdaycnfyopovohafamfryxokcszsxkihpjhswms...
output:
3
result:
ok single line: '3'
Test #32:
score: 0
Accepted
time: 2ms
memory: 5196kb
input:
uacxtttozkcjyxssksfpmxwymchyhsobssbllwbngfwgepyojfdveawredplvfppyqalmeyvlxbsmcgvhmtmopfsuwfrbugbminzonwckxuybcwlqpzegeycaevdadhnnwocjkgwjauleqyvhxbpdarfgmkirrvfnljxvpvfrpsviqqppufswyzcnjmebkjovsnrhkyyaqwkiobxiirehqiuzvycfktacitmtrmvjifrxgofrfkyxuuzpubweuzjdsvymhtvsynpgdwxlixidrhumjrqfqzkkwiwebsybhnk...
output:
1
result:
ok single line: '1'
Test #33:
score: 0
Accepted
time: 2ms
memory: 5420kb
input:
obncmueifwcccegxvkszhqkrnpmeyvmnwbpkxvsctufvaluvvmxfchwsxkwxfkmdnbpkwhopdtmehgbesyjxifphsnezzrfmuuytcmkhgznnfptapdxxkoecdlecejqydothaepidexktrkjujiexpjcangeywebmylpccxhgxtaoelkpvqpkbrkqyoowtsjtdyxhvenuzpifcuvynkiodvfbltyenjzqhwzecnzccjhheefropfskmvwivcvecolynqdarffaoogttxjifdtrbrbwtxbvlowyezbxgiyuwe...
output:
2
result:
ok single line: '2'
Test #34:
score: 0
Accepted
time: 0ms
memory: 6744kb
input:
bcqatarjdfzvabdynnqexqgutwlrxbtadjdyjujpzikbknbxcrezkkwdjhvgioinzlllhvagdmjncllecrembasmjnurddgeqrpymrgseqfgbskfjqunqmzzbwsgzykpqcpetwwzmchpwuwiksvbgwahstpttaljeaoxwmzkqgznayxlqsoxqogljwedwpoasezorabhhawjatwrnkogburmqxroniqhmsxfsypbznnzhjswwicxfvlvtdmilepzymfrlwumjhnqrgppqtmvpztiefqplhrktydguxsdhiwa...
output:
-1
result:
ok single line: '-1'
Test #35:
score: 0
Accepted
time: 3ms
memory: 6960kb
input:
lcilalfjkasdtvoaqixcyuskcezhfzgsepfgclponhriefixpgzncsagyzodawvenalpnafdkylqfwnucpighknhldklzhqnjbexbkankngqjtknkuurehypkkbltrydsfcvrelbtrrdmcqxwkqbtrsfbvrvmragweenippdiggukzrhlikfzekcabzmtbvrfzfpqwtyebspamymwirxmdbmhbbacytkxybnwulbwfsyrqkpadmohodorgqvejfbkhqgddjbidactktvqgmxwpnnvfiboqeaxujcxuehyelt...
output:
2
result:
ok single line: '2'
Test #36:
score: 0
Accepted
time: 3ms
memory: 7072kb
input:
wwjucpbthcaienbdkgxfwpptwgzxumytkhnnyoigsjowyrbixyqupfplnojkdjdpqqcognwywmxwdygbzwxoemctdndiwixmyccgpzhnlejpersdorsudwpijtqhbqvcsxkjyrykxjbcavfqmzkrvccgxsnakiceipngilsgwtkxqpncrawoeyvbskbdtghbvxjdkclhxveontsevoszopahackvktyhqhmbjykhvoxijpofgjguyjbynntxjrezbqckqmtmcqumgltmubiskktxzouiiakjrmvhbptdfqrl...
output:
2
result:
ok single line: '2'
Test #37:
score: 0
Accepted
time: 6ms
memory: 10712kb
input:
euajjxjlrejaxbyvxobwfcuruietgnnmhoxrlheelpfktfgqvhpbllufuyacooqxcoqpvxvimatfhzydipgtaaawbaarorosfhjcefmshfapgyuonajpcjmdmmucflvmugoyldsvismrqgffirxkcjqoxmrfxortuirilmdvepmxxuefnbppmhgmuzrtnknjsgrfswbxnpwkjarwcjoqqucktveigtrazlgsjjrxanjkpdirmykcsmpnivvqopqnayhjjyiknswdvewjdgnxvcldzivnxldxkkjtlrfylbbi...
output:
3
result:
ok single line: '3'
Test #38:
score: 0
Accepted
time: 6ms
memory: 10740kb
input:
ryqikpuwkabqupuqkxvqocdyzphkqsxksnsccobpqcflrzddzzundzneowphpmrhclmgznvppcahegkffgskfhouedbvsueufqaefyvvayeeeojlxdvcnjyrpbohvubcndisbepeetiikuvhzqlmbkfqnvxjqaldguxhapneiyousjbtzpgcbltohsxzvlebhbkjsynbydvsmzlnqrprfkfoffnaqtdzwpippxsnanfmorzekqxrddfikukanpbmejbugthgipuzgvfsndkqirasmmubbvpigqcmlluuaqvi...
output:
3
result:
ok single line: '3'
Test #39:
score: 0
Accepted
time: 0ms
memory: 10788kb
input:
qfwcuvpxrmdracykkzznjqjuohtsztqpaotwkitdxyuzcvmnwlafdmztvsounemptfmfqhipgfoiaaxwoadtocnjwbgmhsbczpjrxugdzvnbvnzlncfdgumcxsoeksjmhsdemkjnfzocmnobrvexpqcmlsqxkbjuupyizkwgjkkvaawtvctksvwfppdaqowmduveermpdxkfxizvkuffpekgtpglgcyjztqfmcvrbhxzqywcsbjjfwpalymrckddftjrxgkznhafhwkbxtkfpcfdcrwedbiiwtbuzmvovvud...
output:
-1
result:
ok single line: '-1'
Test #40:
score: 0
Accepted
time: 4ms
memory: 20200kb
input:
qepycslklynhzkkruaucaztyrazoomsgqhevzrfmpuvpefiahffieyixajlovfuomylnsschmxytfhvmoawuyfryoeomkicyjnobfqktpjmusijgkfcjmtjdxyphirirgwunmfgdqvykdhsnouybnkemkvuuoemuaihopprfkrrpajfpddsspyfbtbwhfkdfsmtibmpmejbgsgvwmpqdnvfgwbpdluidgdnisfwwoxeigagsrxvfsanrdfuozfsikhqcomaelfnrhtlyqjdlltcpyyfzdzhohzqxntczypsf...
output:
3
result:
ok single line: '3'
Test #41:
score: 0
Accepted
time: 4ms
memory: 20480kb
input:
pjpylsynxoiagfroxaynqykxlarebqcqcuqpmocjemlnredrfbevzptnrmtuevngpdxcuznanznfdqwkucgttbilnbfrzuaoyxquzgumhktmcpxwudsngaytegmdaotammunsrbzbvldkkaepsuvusoayddbrxbfjysdpucqrpvdcxkrrenmwbmxgsyyrbfczyhoulglaeqcbautejhbkvatnargbwkdwrtscaffgwjhwfcbojebfguugndjlnokficjkkoqgazefchulnvstrnbesnrfbbmjgwtqmlymles...
output:
1
result:
ok single line: '1'
Test #42:
score: 0
Accepted
time: 3ms
memory: 20500kb
input:
bcqatarjdfzvabdynnqexqgutwlrxbtadjdyjujpzikbknbxcrezkkwdjhvgioinzlllhvagdmjncllecrembasmjnurddgeqrpymrgseqfgbskfjqunqmzzbwsgzykpqcpetwwzmchpwuwiksvbgwahstpttaljeaoxwmzkqgznayxlqsoxqogljwedwpoasezorabhhawjatwrnkogburmqxroniqhmsxfsypbznnzhjswwicxfvlvtdmilepzymfrlwumjhnqrgppqtmvpztiefqplhrktydguxsdhiwa...
output:
-1
result:
ok single line: '-1'
Test #43:
score: 0
Accepted
time: 4ms
memory: 21012kb
input:
vfitessxgeejhcxbbtxlnvvrhzfvngpkoxespwpxavgjafnbykolfjfnlkiatzkhwobnmqlpntynzlqxwgjdqosdacdtbncxedlqvyflreaqrrqpxbtprnsrqvnrlprpvefqclbvrcokveauhvkyiepacesnulcpphhtujonneyikaerxopfvfixjamflowcxevunljcqhmajqughjocqwbcynhldenaikwxxgbnpnqzdkhkvxomtrotexghbtklfikdolsgakhgwossmhehyudfrjovfygkjtpxgkfhumpt...
output:
2
result:
ok single line: '2'