Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using lli = long long;
- const lli INF = 2e18;
- const lli PB = 98765431;
- int main(){
- int n;
- scanf("%d", &n);
- string str;
- cin >> str;
- lli rem = 1, hsh = 0;
- for(int i = 0; i < n; i ++){
- if(i != 0) rem = rem * PB;
- str[i] -= '0';
- hsh = hsh * PB + str[i];
- }
- lli cmp = hsh;
- for(int i = 0; i < n; i ++){
- hsh = hsh - (rem * str[i]);
- hsh = hsh * PB + str[i];
- if(hsh == cmp){
- printf("%d", i + 1);
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement