QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560804#8668. 回文路径SpadeA2610 106ms7796kbC++142.4kb2024-09-12 18:05:042024-09-12 18:05:04

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 18:05:04]
  • 评测
  • 测评结果:0
  • 用时:106ms
  • 内存:7796kb
  • [2024-09-12 18:05:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template<class T1,class T2> bool cmax(T1& a,const T2& b){return a<b?a=b,1:0;}
template<class T1,class T2> bool cmin(T1& a,const T2& b){return b<a?a=b,1:0;}
#define fir(i,x,y,...) for(int i(x),##__VA_ARGS__;i<=(y);i++)
#define firr(i,x,y,...) for(int i(x),##__VA_ARGS__;i>=(y);i--)
#define fird(i,x,y,d,...) for(int i(x),##__VA_ARGS__;i<=(y);i+=(d))
#define firrd(i,x,y,d,...) for(int i(x),##__VA_ARGS__;i>=(y);i-=(d))
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define ll long long
#define ull unsigned long long
int T;
bool _mul=0;
ll gcd(ll x,ll y){if(!y) return x;return gcd(y,x%y);}
ll power(ll b,ll p,ll mod){ll res=1;while(p){if(p&1) res=res*b%mod;b=b*b%mod;p>>=1;}return res;}
const int N=1e5+5,base=131,mod=1e9+9;
ll f[2][N],g[2][N],pw[N];
int n,ans;
char s[N],t[N];
bool check(int opt,int x,int y,int mid)
{
    if(opt==0) return ((f[0][y+mid-1]-f[0][y-1]*pw[mid]%mod)%mod+mod)%mod==((f[1][x-mid+1]-f[1][x+1]*pw[mid]%mod)%mod+mod)%mod;
    if(opt==1) return ((g[0][y+mid-1]-g[0][y-1]*pw[mid]%mod)%mod+mod)%mod==((g[1][x-mid+1]-g[1][x+1]*pw[mid]%mod)%mod+mod)%mod;
    return ((g[0][y+mid-1]-g[0][y-1]*pw[mid]%mod)%mod+mod)%mod==((f[1][x-mid+1]-f[1][x+1]*pw[mid]%mod)%mod+mod)%mod;
}
int get(int opt,int x,int y)
{
    int l=0,r=min(x,n-y+1);
    while(l<r)
    {
        int mid=(l+r+1)>>1;
        if(check(opt,x,y,mid)) l=mid;
        else r=mid-1;
    }
    return l;
}
void solve()
{
    cin>>n>>(s+1)>>(t+1);
    pw[0]=1;
    fir(i,1,n) pw[i]=pw[i-1]*base%mod;
    fir(i,1,n) f[0][i]=(f[0][i-1]*base%mod+s[i])%mod,g[0][i]=(g[0][i-1]*base%mod+t[i])%mod;
    firr(i,n,1) f[1][i]=(f[1][i+1]*base%mod+s[i])%mod,g[1][i]=(g[1][i+1]*base%mod+t[i])%mod;
    fir(i,1,n)
    {
        int len=get(0,i,i);
        cmax(ans,(len+get(2,i-len,i+len-1))*2-1);
        len=get(0,i,i+1);
        cmax(ans,(len+get(2,i-len,i+len-1))*2);
        len=get(1,i,i);
        cmax(ans,(len+get(2,i-len+1,i+len))*2-1);
        len=get(1,i,i+1);
        cmax(ans,(len+get(2,i-len+1,i+len))*2);
        cmax(ans,get(2,i,i)*2);
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    // freopen("1.in","r",stdin);
    //freopen(".out","w",stdout);
    cin.tie(nullptr)->sync_with_stdio(false);
    if(_mul) cin>>T;
    else T=1;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 30
Accepted
time: 1ms
memory: 3628kb

input:

1000
mfmlkrasfiudkzrjzyrlbpitvzfrlmjdzsurtdcmnqpsyfgobbstvplqylvciloomaljyssxtrrccywyirfvlcnchwkfwbdaoxzpfpvlruptganojnfxmnlqetptmlmoyluxvaipghtlaszoozscdmjomobyzboqqmvqjpbfjsoczhkwrlcauzjceqikbaeuiqahnldpqmohfjfzgkbfdbqnoxispkejvpncwsyelebqumapgbfdrjvuaxaphnkciwzkruijmanwslkwosgyfhwbnsthhtxrhrzlgtt...

output:

6

result:

ok single line: '6'

Test #2:

score: 30
Accepted
time: 0ms
memory: 5688kb

input:

1000
wvitzoxwlmhexjuqvoxksetoupgkhattucdzfevqorkdlsymjuvhobdrjsodtipwpfhipsdnyvqtsbbasrrvyybijzmpwseckztnpnkqswgkaeivflhwevhxcchjsnelqcixexkntwiuolsditpdwypgerzijziyrgqkwuucnqaehuwkpyrmwewjitvsaebyytznbtnkulnepceeloyjpfhcdpqfqhvzsmkcynjwztmkbnqaxnikfuiutocahdfbvsgdskgwqmzizzjlbqxnngftdohetabpjzpqzyc...

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Wrong Answer
time: 1ms
memory: 3772kb

input:

1000
abababaabaababbbbabbbbabbbbbbabbbaabbbaababaabaabbabbbbaabbaabaaaabbaaabbbbaaaaaabbbbababaababbaabbbbbbbbabbaababbbbabbaabbbabaaababbaababbbaabaabaababaaababbaaaababbbbbaaabbaabbaaabbaaaaabaaaaaabbbbbaaabbbbbaabbbbababaabaabbbbaaaaababaaaababbbbbbaababbbaaaababaabaabaabaaaaaabbabbabbbbbbbbbbabb...

output:

26

result:

wrong answer 1st lines differ - expected: '28', found: '26'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 20
Accepted
time: 106ms
memory: 7796kb

input:

100000
ibhqhodaqcwqggmckoemulhkgbfidceskhefhsonccepfodalabaqgobpgcnaervbccadkbtsdigsoqochklocgbjjqcdhwrlacamprsoilyhiwkkjalicedhbxajrkhjgivjhnfdibkdwtexnnriegejazmohlfijbeigfmpngncokxhifjfuwuogccdfglfbxobnarmgfhgpnjjewicgfhcmfbbnjbbjjtbprnagpchcihcihfhcikeaecefdgeegtzlfdolhfieahiehdfcaflmndmcojceblf...

output:

9

result:

ok single line: '9'

Test #12:

score: 0
Wrong Answer
time: 105ms
memory: 7680kb

input:

100000
fruiifpdggdnsbgamakpjipicaidfdjpffioqcwioaafbpdagmbbakqpekjabcljockpvcifilcjakhcboolgjbnmmrbeawcjopbccjgncdaucighprheiaqofriccfdbydbhijeelbthsmqbhcddlfemqkvdbflkdrifckarqwlaafifmqibssfukblchalkzdefnccaiabrhcrmisdeiqddccrqhiiwcqqakbfhebkiecahgdlibhgmegkfbuibcarcbajpdeboigeoctdljmqeckdfqahiecla...

output:

10

result:

wrong answer 1st lines differ - expected: '9', found: '10'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%