Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ∧_∧
- ( ・ω・。)つ━☆・*。
- ⊂ ノ ・゜
- しーJ Accepted
- */
- // #pragma GCC optimize("O3")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ll long long
- #define all(x) begin(x), end(x)
- #define x first
- #define y second
- #define int long long
- using namespace std;
- using namespace __gnu_pbds;
- typedef long double ld;
- template<typename T>
- using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
- const ld PI = atan2(0, -1);
- void seriy() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cout << fixed << setprecision(14);
- #ifdef _offline
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const int MAXN = 1e6 + 10;
- const int MAXM = 600;
- const int INF = 1e9;
- const int BASE = 47;
- const int MOD = 1e9 + 7;
- const int MAXLOG = 21;
- const ld EPS = 1e-6;
- vector<int> pw;
- int get_hash(string s) {
- int h = 0;
- for(int i = 0; i < s.size(); i++) {
- h += s[i] * pw[i];
- h %= MOD;
- }
- return h;
- }
- signed main() {
- seriy();
- int n;
- cin >> n;
- pw.resize(MAXN);
- pw[0] = 1;
- for(int i = 1; i < MAXN; i++) {
- pw[i] = pw[i - 1] * BASE;
- pw[i] %= MOD;
- }
- string s, t;
- cin >> s >> t;
- int c = INF, f = INF;
- for(auto i : s) {
- c = min(c, (int)(i - 'a'));
- }
- for(auto i : t) {
- f = min(f, (int)(i - 'a'));
- }
- for(int i = 0; i < n; i++) {
- s[i] -= c;
- t[i] -= f;
- }
- int h = get_hash(s);
- int g = get_hash(t);
- for(int i = n - 1; i >= 0; i--) {
- g = (g - t[i] * pw[n - 1] + MOD * MOD) % MOD;
- g *= BASE;
- g %= MOD;
- g += t[i];
- g %= MOD;
- if(g == h) {
- cout << "Success\n";
- cout << i << " " << f - c << '\n';
- return 0;
- }
- }
- cout << "Impossible";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement