QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#194847#7512. Almost Prefix Concatenationucup-team484#TL 721ms22036kbC++202.2kb2023-09-30 23:00:312023-09-30 23:00:31

Judging History

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

  • [2023-09-30 23:00:31]
  • 评测
  • 测评结果:TL
  • 用时:721ms
  • 内存:22036kb
  • [2023-09-30 23:00:31]
  • 提交

answer

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

const int MAXN = 1000005;
LL mod = 998244353;
LL p = 31, pw[MAXN];
string s, t;
LL h_s[MAXN], h_t[MAXN];
array<array<LL, 3>, MAXN> suf;

LL bpow(LL b, LL x) {

  LL ret = 1;
  while(x) {
    if(x & 1) {
      ret = ret * b % mod;
    }
    b = b * b % mod;
    x /= 2;
  }
  return ret;

}

LL inv(LL x) {
  return bpow(x, mod - 2);
}

void compute_hash(string &s, LL h[]) {
  h[0] = s[0] - 'a' + 1;
  for(int i = 1; i < s.size(); ++i) {
    h[i] = (h[i - 1] + pw[i] * (s[i] - 'a' + 1)) % mod;
  }
}

LL hash_interval(LL h[], int l, int sz) {
  LL ret = (h[l + sz - 1] - h[l - 1] + mod) % mod;
  ret = ret * inv(pw[l]) % mod;
  return ret;
}

int get_next(int ls, int lt) {
  if(s[ls] != t[lt]) {
    return 0;
  }
  int r = min(s.size() - ls + 1, t.size() - lt + 1), l = 0;
  while(l + 1 < r) {
    int m = (l + r) / 2;
    if(hash_interval(h_s, ls, m) != hash_interval(h_t, lt, m)) {
      r = m;
    }
    else l = m;
  }
  //cout << "bs: " << ls << " " << lt << " " << l << " " << r << endl;
  return l;
}

int main() {
    
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> s >> t;
  pw[0] = 1;
  for(int i = 1; i < MAXN; ++i) {
    pw[i] = pw[i - 1] * p % mod;
  }
  compute_hash(s, h_s);
  compute_hash(t, h_t);

  suf[s.size()] = {0, 0, 1};
  for(int i = s.size() - 1; i >= 0; --i) {
    int len = get_next(i, 0);
    if(len < t.size() && i + len < s.size()) {
      ++len;
    }
    //cout << len << endl;
    if(len < t.size() && i + len < s.size()) {
      len = len + get_next(i + len, len);
    }
    auto [a,b,c] = suf[i + 1];
    auto [a2, b2, c2] = suf[i + len + 1];
    LL a3 = (a - a2 + mod) % mod, b3 = (b - b2 + mod) % mod, c3 = (c - c2 + mod) % mod;
    suf[i] = {(a + a3 + 2*b3 + c3) % mod, (b + b3 + c3) % mod, (c3 + c) % mod};
    //cout << i << " len: " << len << " " << suf[i][0] << " " << suf[i][1] << " " << suf[i][2] << endl;
  }
  cout << (suf[0][0] - suf[1][0] + mod) % mod << endl;

}

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 16916kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 9ms
memory: 16064kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 10ms
memory: 16324kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

75038697

result:

ok 1 number(s): "75038697"

Test #4:

score: 0
Accepted
time: 7ms
memory: 16828kb

input:

lvvvllvllvllvllllllllvvvllvlllvvlvlvllvlvvlvvvvlvvllllllvvlvlvvlllvvlvlvllllllvlvvvvvvlllvvvllvlvvvlvvlllvvvvvvlvlllvvvvlvvvvvlvvlvvlllvvllvvllvlvlvlvlvllllvvllvvllvlllvvvllllvvlvvllvvvvlvlvvlvvlllvvvvvvvvlvvlvlllvllvvvvllvvvlvvvvvvlvlllvllllvllllllllvvllllllvlvvlvvvlvllllvllvlvvllllllvlvvvlvlvlvvvl...

output:

538419149

result:

ok 1 number(s): "538419149"

Test #5:

score: 0
Accepted
time: 10ms
memory: 17076kb

input:

fzztyyyfztzzfzyztftyfzyyzzzztyyfzttzttztyzztyyyfyyftyfyfzzffyzffytttzttyzzftyfyfyftyyfzyzffyfyyzztzyyttyfyztfyfzyfzfzyftttfyyfyytzyyzfyyyzztfttzyyytzzffytyzyyyyfzfftftzzztyfftfzfzytftfttytfyzfytzfzztttttzzyztyftzzzfzfzfffttyztzfftfftyfyffztzyffttyyfyfzytytyyttfzzfyyytzzftzyyfftftyytyffzffztfytfyyyty...

output:

867833603

result:

ok 1 number(s): "867833603"

Test #6:

score: 0
Accepted
time: 6ms
memory: 17516kb

input:

xauxlgtqbsianlzjzglalnbtlujfrkfdqgczpmididmtamzeablrbrbjgtsdkzzcfhvcpdawqkrgdsereirlxbizhbsxlcbtgwwshekbhatqonvgupswcowythifpoubxkuoxuuisnzolzwektdcaouxbkhofvdqzmjulmhgqjxwzhgrzmorhqkgekntbzsxgvjtehfbterrhhjhqggzrqiqmcshzwpfoburpyfoehqgtitesyaekhlzcvxzdqmunyrlrhbrjoigdjzpcgptyoiowwnmqrxucxixxydurbdh...

output:

301464023

result:

ok 1 number(s): "301464023"

Test #7:

score: 0
Accepted
time: 23ms
memory: 16068kb

input:

tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt...

output:

816920406

result:

ok 1 number(s): "816920406"

Test #8:

score: 0
Accepted
time: 22ms
memory: 15944kb

input:

cxccxccccxccxccxcxxxccxxcxcxcxcxxcccxcxccccccxccccxccxcxcxxcxxcxcxxxcxcccxcxxxxxccxxcccxxccxxxccxccxxxxcxxccccxccxxcccxcccxxxccccxcxcxccccxxxxccxxxxxcxxxxxxcxxccxxcxcxcxxxxxcxxccxcxxxcccxcxxxccccccccxxxcccxcxxcxxxxccxxxcccccxcccxccccccxxcccxxcccxxxccxxcxccxcccxxxccxccxxxccxcxxxxccxxcxcxxcxxccxxxcxcx...

output:

206627037

result:

ok 1 number(s): "206627037"

Test #9:

score: 0
Accepted
time: 14ms
memory: 16568kb

input:

vmqvvbbmvmmmqqvqvmmbbvqbqvbmmbqmvvbmmmqvqvbvqqmvbbmmvmvqbvmqqbqvqqvmvmmbqvvbvmvbqmqqbqqqbqqmvvmmbvvvbvvvbmqqvbqbmvvmvqqvbqbvvvqmvvvmvqqmvqbmbvmvmqmmbmqqqbbmvqbqbbqqbmmvmmqqqvvvqqqqqmmvvvvqmvmmmmvmqmqbbvbvvqmmmqbbmvqvmvmqbqbbbmqbqbqmqbqmqbmvvqmmvbmmbvbqqvmmmbbmbbmvmmvbmqmqbbqqbqqbbqmbmmmqbqbmvbmvmmmm...

output:

460659355

result:

ok 1 number(s): "460659355"

Test #10:

score: 0
Accepted
time: 10ms
memory: 16796kb

input:

xthikaxiescbqjzrpgtcpigqjsojlsxsiowkkzsdsgscoolhdtglvpgcoggzqnnjmocvanrogbzqjcmijoukjicadaakehxgjphjgnskjvfneoyaucfadilscsucjgweuzcdfapfnrfffdowxvzkvgqzmtszjldylvehzjlvmhproaehqhuwdoadenqdrqwrlxxfouzqolwbopmkpjshczocnnsxktxozahzwqpwbmvexguvjhbvbjwsdtgaitoqwsfzkwnzgeidkamgcfhzhitfxenunlcsbsesbczvmmbu...

output:

906223232

result:

ok 1 number(s): "906223232"

Test #11:

score: 0
Accepted
time: 706ms
memory: 21960kb

input:

bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

39285513

result:

ok 1 number(s): "39285513"

Test #12:

score: 0
Accepted
time: 721ms
memory: 19920kb

input:

hghggghghhghhgghgggghhghhhgghggghghhhhghghgggghhggggghhgghggghhhghggghghghggghggghgghhhghgggghghghgggghhhhhgghhgghhhghhghhhghhhhhhghghhgggggghghgggghghhghhgghhghhhhhhghgghhghghgggghgggggghghhhhhghhhhhhhgghhggggghhgghhhhhhhhghggggggghhghhghhghhgghhghgghhhhgghghghhhhhghggghhhhhhhgggggghgghghhhhghhgggg...

output:

58618935

result:

ok 1 number(s): "58618935"

Test #13:

score: 0
Accepted
time: 152ms
memory: 21984kb

input:

nnttcybbmnrnsuybrkmkmtumcyuyrrmbtybutunsyrkmunmncmkuknttmmtkymtcybttrmyrtckscttcksbtymtyukbbynnnbukttncmbutscbrytbrutnuyuknmtymckkttrrnsbtrkbnnnkbrccrcyybmnnybbkkbcbbccycsrcytnuucbbyytckrycktsmkymruycksrscytkskscbtbccbrurmumrkbkbttkcynmymbbmbkrksmnusryumsmmyrcsmusumbrkkbmsbyytmmruubskccsusnntcuntrrt...

output:

46252951

result:

ok 1 number(s): "46252951"

Test #14:

score: 0
Accepted
time: 63ms
memory: 22036kb

input:

ittaztseqcdirziayobnnxuzipvteycmgjbupnlxuheulnmzsdeymctprlxvkvzjwrotsauxagyrqcwzuwqyodrqsupwpyrmbwjqlvfdsrocneigxvnjfiseotxmutzwacfutqlmzmxwuqgjugwkafnxvzutgbrweqrdshwneksgxzzinnmbbioqdvbmavukaegvkpwauuoysklelsqhytlikpdpymbwhmbdmrycaiywtwjjqtecwoofyjhbumjtipwyopkuralejvopitpjcdswcvsugimgbrlibrteaqtb...

output:

838361918

result:

ok 1 number(s): "838361918"

Test #15:

score: -100
Time Limit Exceeded

input:

llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...

output:


result: