QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#761327#5312. Levenshtein DistanceASnownTL 3965ms6468kbC++175.7kb2024-11-18 22:05:102024-11-18 22:05:11

Judging History

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

  • [2024-11-18 22:05:11]
  • 评测
  • 测评结果:TL
  • 用时:3965ms
  • 内存:6468kb
  • [2024-11-18 22:05:10]
  • 提交

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;
ll 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]%P+P)%P==(ht[b+mid]-pw[mid]*ht[b]%P+P)%P)
         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)%P;
   for(int i=1;i<=n;i++) hs[i]=(hs[i-1]*B+s[i])%P;
   for(int i=1;i<=m;i++) ht[i]=(ht[i-1]*B+t[i])%P;
   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: 100
Accepted
time: 0ms
memory: 4084kb

input:

4
aaa
aabbaab

output:

0
5
15
7
1

result:

ok 5 number(s): "0 5 15 7 1"

Test #2:

score: 0
Accepted
time: 3965ms
memory: 4952kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 31 numbers

Test #3:

score: 0
Accepted
time: 579ms
memory: 6376kb

input:

30
BBAAABAABBBA
ABBABBBBAABAAAABABBBAABAABBAABAAAAAABAABABBAAAABAAAAABABAABAABBABBAAAABBBBAABBABAAABAABAABBBBBABBABABBBBABBBBAAABBABABBBBAAABBBBAAAABABABABABABABAAABBBBBAABAABAABBAABBBAABBBBBBBABAABAABAABABAABAAABAABBBAABABBABBAAABAAAABABABBABBBAAABBBAAAABBBBABABABAABAABBBBBBBBBAABBBABABBBABAABBABBA...

output:

17
662
8230
50302
166666
310121
345469
280387
227200
209178
203013
198561
105117
102147
99771
97730
96058
94730
93633
92720
92060
91525
91143
90831
90585
90419
90288
90200
90120
90068
90035

result:

ok 31 numbers

Test #4:

score: 0
Accepted
time: 1622ms
memory: 5340kb

input:

30
AAABBAAAAAAAAAAAAABAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAABAAAAABAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABABAAAABAAAABAAAABAAAAABAAAAAABAAAAAAAAABAAABAAABBAAAAAAAAAAAAAAAABAABAAABAAAAAAAAAAAAABAAAAAAAAAAAAAAAABAAABBAAAAAAAAAAAAAAAAAAAAAAAAAABAABAABABAAAAAAAAAAAAAAA...

output:

0
0
0
0
1
28
263
1410
6434
22523
56017
115080
189633
263874
316906
339254
332825
312943
286470
263283
246310
235032
227182
221294
216978
213734
211178
208848
206945
205393
204279

result:

ok 31 numbers

Test #5:

score: 0
Accepted
time: 619ms
memory: 5620kb

input:

30
ABABAABAAABAAAA
AABBABABBBBBAAABABAABBAAABBBAABABBBABABABABABBABBBAAAAABBAAABBABABABABABBAAABBAAABAAABBBBBBBAABABBBAAAAABAABBBABBABBBABBBABABAABABBBAAABBABBAAABBBBBBBAABAABABAAAAAABBAABAAABBBAABBAABBAABBABABAAAAAAAABBBBBAAABABABBABAAAAABAABAABAABAABAAABABBABBBABAAABBBABABAABAABBBAABABBAABBAAAABAB...

output:

2
125
1938
15793
70756
178090
282937
325020
310617
277899
244094
217672
206966
202456
198644
105535
102767
100355
98411
96655
95310
94124
93217
92487
91872
91414
91039
90741
90555
90397
90276

result:

ok 31 numbers

Test #6:

score: 0
Accepted
time: 1963ms
memory: 6468kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0
0
0
0
1
91
1082
14598
58877
123681
212928
258264
253856
277926
265254
243456
217809
198008
190004
184665
184470
183593
183524
183406
183335
183255
183185
183142
183078
182991
182922

result:

ok 31 numbers

Test #7:

score: 0
Accepted
time: 796ms
memory: 5628kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAABABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

1
460
44032
126686
201431
222795
213509
199190
187254
184699
184159
183907
183818
183558
183500
183466
183412
183393
183343
183299
183275
183236
183163
183127
183105
183056
183010
182971
182910
182719
182437

result:

ok 31 numbers

Test #8:

score: 0
Accepted
time: 808ms
memory: 5340kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

29
25121
100687
175758
199099
210112
187931
180903
178707
178497
178494
178497
178495
178496
178492
178492
178492
178491
178490
178491
178490
178490
178492
178489
178489
178488
178487
178487
178487
178488
178487

result:

ok 31 numbers

Test #9:

score: 0
Accepted
time: 867ms
memory: 5592kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

17
12879
77552
170649
187824
198210
200962
189247
181730
180843
178608
178607
178607
178605
178599
178599
178599
178596
178595
178592
178594
178595
178593
178594
178593
178595
178593
178593
178594
178593
178591

result:

ok 31 numbers

Test #10:

score: 0
Accepted
time: 1984ms
memory: 6208kb

input:

30
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0
0
0
0
73
320
52858
125690
177498
270124
217932
192611
177148
228465
180709
166240
162360
162360
162359
162359
162359
162359
162358
162358
162359
162357
162357
162357
162357
162358
162358

result:

ok 31 numbers

Test #11:

score: 0
Accepted
time: 914ms
memory: 5432kb

input:

30
ABBABABABAAABAAAAAAABAAABBAAAA
BABBABBBAAABBAAAAABBBBBAAAABAAAAAABBAABAAAABAAABAAAAAAAABAAABAABAABAABBBAAAABAAAABABBABBAAABABAAAAAAAABAABBAAAAAABABAAAAABABAAAAAAABAAAAAAAABAAABBBAAAAABAABAABAAAAABAAAAAAAAAAAABABAAAABABAAAABAABBAAAAABBAAABABBBBBBAABABAAAAABABBBAABABBAAAABAAAAABABABBAAAAAAAABABBBAB...

output:

0
0
1
38
617
4567
22647
76780
180046
296249
362349
361655
325883
289074
263906
246552
233312
221488
212319
205320
200921
198057
196229
194923
193749
192649
191581
190728
189773
188925
98116

result:

ok 31 numbers

Test #12:

score: 0
Accepted
time: 563ms
memory: 5780kb

input:

30
Y3YYY
wwwwwwwYYwwwww3ww3w33Yww3wYY3w3w33w3Y3YY33wYwY33wwYwY33Y3w3wwwY333ww333Ywww3w3Y33wwYw3YYwY3Y3w33YwwwwwYYYw3YYYYYYww3w3333Yw3Y3wY3wYw3w3w3Y3w33YY33YwwY3Y3wY33w3333Yw333wYYw3Yw33w3YwYYYYYwwwwY3wwYYYYY33Y3YwYY3Yw3www3Ywww333w3YYY333YY3Y3333Y3Y33ww33333wwYY3YYYww3YYYYYYwwYYYwwYY33Y33wYY3w3wY3w3...

output:

412
9896
68598
212288
338054
201716
131998
125202
120710
117075
114099
111708
109603
107820
106320
105086
104074
103198
102592
102094
101640
101290
101006
100767
100571
100430
100305
100226
100158
100109
100074

result:

ok 31 numbers

Test #13:

score: 0
Accepted
time: 2908ms
memory: 5532kb

input:

30
BnAnnBB3fn33BffBBn3nfAABnBnfBfffBfBAf3Ann3nnfAnAAA
3Bn33ABnBnn3ffnfnnn3fB3Af33fBf3fnnBnBAAffBB33BnB3A3nBAnnABnf33AAAB3nnBA33nf33n3nBfnfnfABB3nBAA3ABAnAAB33A33ABfnAnA33f3fBBnBBfBnB3f3BBf3AAfBAAB3A3BnffBnf33nnffA33fAnffnBBB3nnBBfnBB33BffABn3n3BnAffBBA3nnnAfBfBnn3nn3fn3fn3B3AB3fBn3ABf3BAfAnAB3AAABB3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
71
377
1675
6225
20231
54946
129079
258834
431560

result:

ok 31 numbers

Test #14:

score: -100
Time Limit Exceeded

input:

30
BlXI1hCXN7XMD3h6ZFl8BFVBTgyh3R8oo74unTVVFKwjZCUjTzGqap3FSDU7KxycOFmh1au29Me8OEuSkS4Hd7DAzMVznUbBNuf3pqpud9t2B8F2M1OYziAPbmNynplDCtD3gbIkwSWV6H7Z2Uw4X12pPkFHM5Aisr4uVqggN2hdZGEhEVXNTbHSJ2teCsrO8pRUzKOnYDXIJ3hpkgELyRc7bn8UgQ2Rnhf4r2QA9kQqSSjqrCjGmzicFB9KjqOS2hq75WZRb1ZoI9cPyeOsYE6K9egR12hYCazoIQH8O...

output:


result: