QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762669 | #5312. Levenshtein Distance | AlicX | WA | 0ms | 3812kb | C++14 | 5.6kb | 2024-11-19 16:05:39 | 2024-11-19 16:05:41 |
Judging History
answer
#include<bits/stdc++.h>
#define file(F) freopen(#F".in","r",stdin),freopen(#F".out","w",stdout)
#define lowbit(x) ((x)&-(x))
#define ALL(x) (x).begin(),(x).end()
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define popc(x) (__builtin_popcount((x)))
#define abs(x) ((x)>=0?(x):-(x))
using namespace std;
using ll=long long;
using ull=unsigned long long;
using uint=uint32_t;
template<typename T>
inline bool Max(T &x,T y) { return std::less<T>()(x,y)&&(x=y,true); }
template<typename T>
inline bool Min(T &x,T y) { return std::less<T>()(y,x)&&(x=y,true); }
void Solve();
namespace asnown {
using i64=int64_t;
using u64=uint64_t;
using u128=__uint128_t;
namespace isPrime {
constexpr u64 qpow(u64 a,u64 b,u64 p) {
u64 res=1;
for(;b;b>>=1,a=a*a%p)
if(b&1) res=res*a%p;
return res;
}
constexpr bool checkPrime(u64 p) {
if(p==1) return false;
u64 d=__builtin_ctzll(p-1),s=(p-1)>>d;
for(auto a:{2,3,5,7,11,13,82,373}) {
if(a%p==0) continue;
u64 x=qpow(a,s,p),y=0;
for(int i=0;i<d;i++,x=y) {
y=(u128)x*x%p;
if(y==1&&x!=1&&x!=p-1)
return false;
} if(y!=1) return false;
} return true;
}
}
// gen prime in [L,R)
template<u64 __start=0>
constexpr u64 genPrime(u64 l,u64 r) {
using isPrime::checkPrime;
u64 x=__start^0x113817;
for(char c:__TIME__ __TIMESTAMP__)
x+=c,x^=x<<13,x^=x>>7,x^=x<<17;
while(true) {
x^=x<<13,x^=x>>7,x^=x<<17;
auto y=l+x%(r-l);
if(checkPrime(y)) return y;
} return 0;
}
}
namespace asnown {
using i32=int32_t;
using u32=uint32_t;
using i64=int64_t;
using u64=uint64_t;
using i128=__int128_t;
using u128=__uint128_t;
constexpr i32 inverse(i32 a,i32 m) {
i64 r=1;
while(a>1) { r=r*(m-m/a)%m,a=m%a; }
return r;
}
template<i32 m>
class static_modint {
using mint=static_modint;
public:
constexpr static_modint() : v(0) {}
constexpr static_modint(i32 v) : v(normal(v%m)) {}
constexpr static_modint(u32 v) : v(v%m) {}
constexpr static_modint(i64 v) : v(normal(v%m)) {}
constexpr static_modint(u64 v) : v(v%m) {}
constexpr static_modint(i128 v) : v(normal(v%m)) {}
constexpr static_modint(u128 v) : v(v%m) {}
constexpr u32 normal(i32 v) { if(v>=m) v-=m; return v+((v>>31)&m); }
constexpr u32 val() const { return v; }
constexpr static u32 mod() { return m; }
constexpr explicit operator bool() const { return v; }
constexpr mint inv() const { assert(v!=0); return mint(inverse(v,m)); }
constexpr mint pow(i64 b) const { assert(b>=0);
mint a=*this,res=1; for(;b;b>>=1,a*=a) if(b&1) res*=a; return res; }
constexpr mint operator+() const { return *this; }
constexpr mint operator-() const { return mint()-*this; }
constexpr mint& operator+=(const mint &p) { return v=normal(v+p.v),*this; }
constexpr mint& operator-=(const mint &p) { return v=normal(v-p.v),*this; }
constexpr mint& operator++() { return (*this)+=1; }
constexpr mint& operator--() { return (*this)-=1; }
constexpr mint& operator++(i32) { auto tmp=*this; return ++*this,tmp; }
constexpr mint& operator--(i32) { auto tmp=*this; return --*this,tmp; }
constexpr mint& operator*=(const mint &p) { v=i64(v)*p.v%m; return *this; }
constexpr mint& operator/=(const mint &p) { return *this *= p.inv(); }
constexpr friend mint operator+(const mint &p,const mint &q) { return mint(p)+=q; }
constexpr friend mint operator-(const mint &p,const mint &q) { return mint(p)-=q; }
constexpr friend mint operator*(const mint &p,const mint &q) { return mint(p)*=q; }
constexpr friend mint operator/(const mint &p,const mint &q) { return mint(p)/=q; }
constexpr friend mint operator++(mint &v,i32) { auto tmp=v; v+=1; return tmp; }
constexpr friend mint operator--(mint &v,i32) { auto tmp=v; v-=1; return tmp; }
constexpr friend std::istream& operator>>(std::istream &is,mint &a) { i64 v; is>>v; a=v; return is; }
constexpr friend std::ostream& operator<<(std::ostream &os,const mint &a) { os<<a.val(); return os; }
constexpr bool operator==(const mint& p) const { return val()==p.val(); }
constexpr bool operator!=(const mint& p) const { return val()!=p.val(); }
private:
u32 v;
};
using modint998244353=static_modint<998244353>;
using modint107=static_modint<1000000007>;
};
const int P=asnown::genPrime<>(9e8,1e9),B=asnown::genPrime<P>(100,300);
// using hint=asnown::static_modint<P>;
const int N = 1e5+15;
int n,m,k;
string s,t;
ull pw[N],hs[N],ht[N];
int f[35][65],ans[N];
int LCP(int a,int b) {
int l=0,r=min(n- --a,m- --b),mid;
while(l<r) {
mid=l+r+1>>1;
if(hs[a+mid]-pw[mid]*hs[a]==ht[b+mid]-pw[mid]*ht[b])
l=mid; else r=mid-1;
} return l;
}
signed main() {
#ifndef ONLINE_JUDGE
#endif
cin.tie(nullptr)->sync_with_stdio(false);
Solve();
}
void Solve() {
cin>>k>>s>>t;
n=s.size(),s=' '+s,m=t.size(),t=' '+t;
// k=30,n=1e5,m=1e5;
// for(int i=1;i<=n;i++) s+='a';
// for(int i=1;i<=m;i++) t+='b';
pw[0]=1; for(int i=1;i<=max(n,m);i++) pw[i]=pw[i-1]*B;
for(int i=1;i<=n;i++) hs[i]=hs[i-1]*B+s[i];
for(int i=1;i<=m;i++) ht[i]=ht[i-1]*B+t[i];
for(int l=1;l<=m;l++) {
memset(f,0,sizeof f);
for(int i=0;i<=k;i++) for(int j=-i;j<=i;j++) {
int t=j+k;
f[i][t]+=LCP(1+f[i][t],l+f[i][t]+j);
if(i==k) continue;
Max(f[i+1][t],f[i][t]+1);
Max(f[i+1][t-1],f[i][t]+1);
Max(f[i+1][t+1],f[i][t]);
}
for(int j=max(-k,1-n);j<=min(k,m-l+1-n);j++)
for(int i=0;i<=k;i++) if(f[i][j+k]==n)
{ ++ans[i]; break; }
}
for(int i=0;i<=k;i++) printf("%d\n",ans[i]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
4 aaa aabbaab
output:
0 5 12 5 1
result:
wrong answer 3rd numbers differ - expected: '15', found: '12'