Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int MX=5009;
- const ll inf=(1ll<<61);
- const int mod1=1e9+7;
- const int mod2=1e9+9;
- const int p1=29;
- const int p2=37;
- map<string,int>h1[MX],h2[MX];
- void buildhash(string s){
- // for(int i=0;i<s.size();i++)s[i]-='a';
- h1[0][s]=s[0];
- h2[0][s]=s[0];
- for(int i=1;i<s.size();i++){
- h1[i][s]=(h1[i-1][s]*p1+s[i])%mod1;
- h2[i][s]=(h2[i-1][s]*p2+s[i])%mod2;
- }
- }
- bool bn(string s,string s1){
- int l=0,r=s.size()-1;
- int ans=0;
- while(l<=r){
- int mid=(l+r)/2;
- if(h1[mid][s]==h1[mid][s1]&&h2[mid][s]==h2[mid][s1]){
- l=mid+1;
- ans=mid+1;
- }
- else{
- r=mid-1;
- ans=mid;
- }
- }
- if(ans==s.size())return 0;
- return s[ans]<s1[ans];
- }
- bool cmp(string a,string b){
- if(a.size()!=b.size())return a.size()<b.size();
- return bn(a,b);
- }
- string s1="asas";
- string s2="asas";
- int main(){
- buildhash(s1);
- buildhash(s2);
- cout<<bn(s1,s2)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement