QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412336#3168. Letter Wheelslittlecat#WA 0ms3632kbC++14988b2024-05-16 12:00:522024-05-16 12:00:52

Judging History

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

  • [2024-05-16 12:00:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2024-05-16 12:00:52]
  • 提交

answer

#include <iostream>
#include <unordered_map>
#define For(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;
const int mx=5000; typedef long long ll; const ll mod=1000000007;
int a[3][mx], h[mx+1], p[mx+1];
unordered_map<ll,int> m;
void ins(ll x, int i)
{
    if(m.find(x)==m.end()) m[x]=i;
    else m[x]=min(m[x],i);
}
int qry(ll x)
{
    if(m.find(x)!=m.end()) return m[x];
    return 2*mx;
}
int main()
{
    string s[3]; For(t,0,3) cin>>s[t]; int n=s[0].size();
    For(t,0,3) For(i,0,n) a[t][i]=s[t][i]-'A';
    p[0]=1; For(i,0,n) h[i+1]=(h[i]*3+a[2][i])%mod, p[i+1]=(p[i]*3)%mod;
    For(i,0,n) ins((h[n]*p[i]+h[i]*(1-p[i]))%mod,min(i,n-i));
    int ans=2*mx;
    For(i,0,n)
    {
        ll t=0; bool bad=0;
        For(j,0,n)
        {
            if(a[0][j]==a[1][(i+j)%n]) {bad=1; break;}
            t=(t*3+3-a[0][j]-a[1][(i+j)%n])%mod;
        }
        if(!bad) ans=min(ans,qry(t)+min(i,n-i));
    }
    cout<<(ans==2*mx?-1:ans)<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

ABC
ABC
ABC

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3568kb

input:

ABBBAAAA
BBBCCCBB
CCCCAAAC

output:

-1

result:

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