Question link: Click the open link
Question:
2 strings
Delete one of the first strings so that the two strings are identical.
Where can I select?
Ideas:
Calculate the prefix and Suffix in hash, and then enumerate the positions
#include <cstdio>#include <algorithm>#include<iostream>#include<string.h>#include <math.h>#include<queue>#include<map>#include<vector>#include<set>using namespace std;#define mod 100000007#define ll long long#define N 1000050char s[N], c[N];vector <int> ans;ll l1[N], r1[N], l2[N], r2[N];int main(){ int i, j; while(~scanf("%s",s+1)){ scanf("%s",c+1); int len1 = strlen(s+1), len2 = strlen(c+1); if(len1 -1 != len2){puts("0");continue;} l1[0] = 0; for(i = 1; i <= len1; i++) { l1[i] = l1[i-1]*26 + s[i]; if(l1[i]>=mod) l1[i] %= mod; } r1[len1+1] = 0; for(i = len1; i ; i--) { r1[i] = r1[i+1]*26 + s[i]; if(r1[i]>=mod) r1[i] %= mod; } l2[0] = 0; for(i = 1; i <= len2; i++) { l2[i] = l2[i-1]*26 + c[i]; if(l2[i]>=mod) l2[i] %= mod; } r2[len2+1] = 0; for(i = len2; i ; i--) { r2[i] = r2[i+1]*26 + c[i]; if(r2[i]>=mod) r2[i] %= mod; } ans.clear(); for(i = 1; i <= len1; i++) { ll a = l1[i-1] + r1[i+1]; ll b = l2[i-1]+r2[i]; if(a==b)ans.push_back(i); } cout<<ans.size()<<endl; for(i = 0; i <ans.size(); i++) printf("%d%c", ans[i], i==ans.size()-1?'\n':' '); } return 0;}