QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#121779 | #6557. LCSLCSLCS | zhoukangyang | WA | 14ms | 14608kb | C++14 | 2.0kb | 2023-07-08 20:38:42 | 2023-10-12 11:47:23 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector < int >
#define sz(a) ((int) (a).size())
#define ll long long
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
const int N = 2007, mod = 998244353;
int qpow(int x, int y = mod - 2) {
int res = 1;
for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
return res;
}
ll cn, cm;
int n, m;
char s[N], t[N];
ll len[N], LST[N], pr[N];
mt19937_64 orz(time(0) ^ *new int);
void SLV() {
L(j, 1, n) {
char c = s[j];
int lst = 0;
R(k, m, 1) if(t[k] == c) {
if(!lst) {
int cur = k + 1, add = 0;
L(z, 1, m - 1) {
if(cur > m) cur = 1, add = 1;
if(len[cur] > len[k] + add)
swap(len[cur], len[k]), len[cur] += add, len[k] -= add;
++cur;
}
len[k] += 1;
} else {
L(cur, k + 1, lst)
if(len[cur] > len[k])
swap(len[cur], len[k]);
}
lst = k;
}
}
}
ull hsh[N], F[N];
int W[N][N];
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> cn >> cm;
// cn = cm = 1000;
// n = m = 10;
// L(i, 1, n) s[i] = orz() % 3 + 'A';
// L(i, 1, m) t[i] = orz() % 3 + 'A';
cin >> (s + 1) >> (t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
L(i, 1, m) {
hsh[i] = orz();
}
int cnt = min(1000LL, cn);
L(o, 1, cnt) SLV();
cn -= cnt;
cnt = min(1000LL, cn);
L(i, 1, m) pr[i] = len[i];
L(o, 1, cnt) {
L(i, 1, m) LST[i] = len[i];
SLV();
ull ret = 0;
L(i, 1, m) ret += (len[i] - LST[i]) * hsh[i], W[o][i] = len[i] - LST[i];
F[o] = ret;
}
int cyc = 0;
L(i, 1, cnt) {
int ok = 1;
L(j, 1, cnt - i) ok &= F[j] == F[j + i];
if(ok) {
cyc = i;
break;
}
}
L(i, 1, m) len[i] = pr[i];
L(i, 1, cyc) {
ll P = (cn - i + cyc) / cyc;
L(j, 1, m) len[j] += P * W[i][j];
}
ll ans = 0;
L(i, 1, m) ans += min(len[i], cm);
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
input:
10 10 AB BA
output:
19
result:
ok 1 number(s): "19"
Test #2:
score: 0
Accepted
time: 0ms
memory: 12548kb
input:
100000000 100000000 A AB
output:
100000000
result:
ok 1 number(s): "100000000"
Test #3:
score: 0
Accepted
time: 14ms
memory: 14608kb
input:
1000000000000000 1000000000000000 BDCABACCCABBBDBDDCDADACBACBACDDCDCBADDDCDDCBBABDBA DACBBDDBBCADCCACACAACBCBCCCBBABDACAACADAADCDBCCCBB
output:
30999999999999997
result:
ok 1 number(s): "30999999999999997"
Test #4:
score: -100
Wrong Answer
time: 9ms
memory: 12076kb
input:
1000000000000000 1000000000000000 BDDCACBCBCBBAACBBBBACCBADDDCDACCBACCDDDBBDBDBBBCBA CCCCBAADCDCDABADDBCCDACAABADAABCBDCCAADDABADDBCBBC
output:
30999999999999999
result:
wrong answer 1st numbers differ - expected: '30000000000000000', found: '30999999999999999'