QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748804#7780. Dark LaTeX vs. Light LaTeXmonuiCompile Error//C++231.9kb2024-11-14 21:30:262024-11-14 21:30:27

Judging History

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

  • [2024-11-25 20:53:52]
  • hack成功,自动添加数据
  • (/hack/1258)
  • [2024-11-14 21:30:27]
  • 评测
  • [2024-11-14 21:30:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define lowbit(x) x&(-x)
using ll=__int128;
const int N=5010;
const ll M=1e17+3;
string a,b;
unordered_map<int,int> st_a,st_b;
int na,nb;

ll hash_a[N],hash_b[N];
ll fac[N];
void init_init(){
    fac[0]=1;
    for(int i=1;i<N;i++){
        fac[i]=(fac[i-1]*31)%M;
    }
}

void init(string& s,int len,ll* ans){
    for(int i=1;i<=len;i++){
        ans[i]=ans[i-1]*31+s[i]-'a'+13;
        ans[i]%=M;
    }
}

void calc(string& s,int len,unordered_map<int,int>& st,ll* ans,int d){
    vector<vector<int>> op(N,vector<int>(N,0));
    vector<int> lst(N,0);
    for(int i=1;i<=len;i++){
        for(int j=len;j>i;j--){
        	lst[j]=0;
            if(s[i]!=s[j]) continue;
            if(s[i-1]==s[j-1]) lst[j]=lst[j-1]+1;
            op[i+1][j]-=1;
            op[i+1][max(j-lst[j]-1,i+1)]+=1;
        }
    }
    for(int i=1;i<=len;i++){
    	int res=0;
    	ll to=0;
        for(int j=i;j<=len;j++){
        	res+=op[i][j];
            int num=res+d;
            if(num<=0) continue;
            to=(to*31+s[j]-'a'+13)%M;
            st[to]+=num;
        }
    }
}

int getans(string& s,int len,unordered_map<int,int>& st,ll* ans){
    int res=0;
    for(int i=1;i<=len;i++){
    	ll t0=0;
        for(int j=i;j<=len;j++){
			to=(to*31+s[j]-'a'+13)%M;
            res+=st[to];
        }
    }
    return res;
}

void solve(){
    cin>>a>>b;
    na=a.size(),nb=b.size();
    a="#"+a;b="#"+b;
    init_init();
    init(a,na,hash_a);
    init(b,nb,hash_b);
    calc(a,na,st_a,hash_a,1);
    calc(b,nb,st_b,hash_b,0);
    int res=getans(a,na,st_b,hash_a)+getans(b,nb,st_a,hash_b);
    cout<<res<<endl;
}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0); 
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

详细

answer.code: In function ‘long long int getans(std::string&, long long int, std::unordered_map<long long int, long long int>&, ll*)’:
answer.code:59:25: error: ‘to’ was not declared in this scope; did you mean ‘t0’?
   59 |                         to=(to*31+s[j]-'a'+13)%M;
      |                         ^~
      |                         t0